3

我在我的项目(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();
});
4

2 回答 2

4

演示

隐藏搜索框。

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

在按钮单击时显示它。该按钮具有类search

$(document).on('click', '.search', function () {
 $('form.ui-listview-filter').show();
});
于 2013-05-08T12:51:24.423 回答
3

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

<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>

请注意,<form>具有style="display:none;"as inline css

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

$(document).on("click","#BUTTON-SELECTOR",function(){
             $("searchForm").toggle();
});
于 2013-05-08T11:32:26.900 回答