【问题标题】:jquery mobile search buttonjquery移动搜索按钮
【发布时间】:2013-05-08 21:06:00
【问题描述】:

我在我的项目(jQuery Mobile)中实现了一个列表视图,并添加了一个用于搜索的文本框。

但我想首先显示列表视图,并且仅在用户单击按钮进行搜索时才显示列表上的文本框。

这是我的代码:

 <a data-role="button" href="#" class="search">Show Search box</a>

    <ul data-role="listview" data-filter="true" data-filter-placeholder="Pesquisa Contacto..." data-theme="d" data-divider-theme="d" style="padding:10px 10px 10px 10px;top:10px">
      <li>
        <a href="index.html">
          <h3>jQuery Team</h3>    
          <p><strong>Boston Conference Planning</strong></p>
          <p>In preparation for the upcoming conference in Boston, we need to start gathering a list of sponsors and speakers.</p>
          <p class="ui-li-aside"><strong>9:18</strong>AM</p>
        </a>
      </li>
    </ul>

JAVASCRIPT:

$(document).on('pagebeforeshow', '#p33', function () {    
 $('form.ui-listview-filter').hide();
});
$(document).on('click', '.search', function () {
 $('form.ui-listview-filter').show();
});

【问题讨论】:

  • 您想隐藏搜索框,直到点击按钮?
  • 是的,这就是我尝试做的......
  • 我已经在 Ishank 的帮助下更新了代码.. 但说加载页面出错
  • 就是这样......它如何与toogle一起工作?

标签: javascript jquery html jquery-mobile


【解决方案1】:

Demo

隐藏搜索框。

$(document).on('pagebeforeshow', '#pageID', function () {    
 $('form.ui-listview-filter').hide();
});

在按钮点击时显示。该按钮的类为search。

$(document).on('click', '.search', function () {
 $('form.ui-listview-filter').show();
});

【讨论】:

  • Omar...感谢您的帮助...但什么也没发生...我要更改页面 ID 吗?对不起,我是 jquery 的新手
  • 放listview所在的page id。并给按钮一个类search,就像我制作的演示一样。 @user2232273
  • 你添加按钮了吗? @user2232273
  • 是的..喜欢你的..看看我下面的代码......非常感谢你的帮助......
  • 我的意思是&lt;a data-role="button" href="#" class="search"&gt;Show Search box&lt;/a&gt;。欢迎@user2232273 :)
【解决方案2】:

一种方法是 - 将标记设置为 -

<form id ="searchForm"class="ui-listview-filter ui-bar-c" role="search" style="display:none;"><div  class="ui-input-search ui-shadow-inset ui-btn-corner-all ui-btn-shadow ui-icon-searchfield ui-body-c"><input placeholder="Filter items..." data-type="search" class="ui-input-text ui-body-c"><span class="ui-btn-inner ui-btn-corner-all"><span class="ui-btn-text">clear text</span><span class="ui-icon ui-icon-delete ui-icon-shadow">&nbsp;</span></span></a></div></form>
<ul data-role="listview" data-filter="true" data-filter-placeholder="Pesquisa Contacto..." data-theme="d" data-divider-theme="d" 
           style="padding:10px 10px 10px 10px;top:10px">
<li><a href="index.html">           
                <h3>jQuery Team</h3>
                <p><strong>Boston Conference Planning</strong></p>
                <p>In preparation for the upcoming conference in Boston, we need to start gathering a list of sponsors and speakers.</p>
                <p class="ui-li-aside"><strong>9:18</strong>AM</p>      
            </a></li>
            </ul>

请注意,&lt;form&gt; 具有 style="display:none;" 和 inline css。

现在,在按钮单击操作上取消隐藏/隐藏搜索表单 - 类似于 -

$(document).on("click","#BUTTON-SELECTOR",function(){
             $("searchForm").toggle();
});

【讨论】:

  • 我已经用你的解决方案更新了我的代码。但是当我点击按钮时我添加了:错误加载页面,也许我选择了错误的类?
  • 确保您在正确的位置添加 jQuery 部分,并且所有需要的 jQuery 和 jQuery Mobile .js 和 .css 都包含在 html 页面中
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-11-23
  • 2020-12-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多