简体   繁体   English

如何在JQUERY中获取数据过滤器文本框的值

[英]How to get the value of a data-filter textbox in JQUERY

I am attempting to implement multiple data filters within the same application but also want to be able to get the value of the search box if the enter button is selected. 我正在尝试在同一个应用程序中实现多个数据过滤器,但是如果选择了回车按钮,我还希望能够获得搜索框的值。 I know I can get the value of an input search field using $("input[data-type='search']").val() but is there a way to append an id so that I can ensure that I am asking for the right value. 我知道我可以使用$("input[data-type='search']").val()来获取输入搜索字段的值,但是有一种方法可以附加一个id,以便确保我在询问为正确的价值。

Below is one of my pages that is using the data-filter: 以下是我使用数据过滤器的页面之一:

  <div data-role="page" data-theme="b" id="enterNewName">
  <div data-role="header" data-theme="b">
    <a class="leavePageBtn ui-btn-left" data-role="button" data-icon="arrow-l" data-iconpos="left" data-theme="b">Cancel</a>
    <h1>
      Enter Name
    </h1><a class="EnterNameBtn ui-btn-right" data-role="button" data-icon="arrow-r" data-iconpos="right" data-theme="e">Enter</a>
  </div>
  <div data-role="content">
    <ul data-role="listview" data-inset="true" data-filter="true" id='nameList' data-filter-placeholder="Enter Name...">
    <li>test1</li>
    <li>test2</li>
    <li>test3</li>
    </ul>
  </div>
</div>

Thanks. 谢谢。

This is the best method I have found so far, quite clunky but seems to be working. 到目前为止,这是我发现的最好方法,虽然很笨拙,但似乎正在奏效。 I wish there was a way to specify an id. 我希望有一种指定ID的方法。

$('#nameList').prev().find(".ui-input-search .ui-input-text").val();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM