简体   繁体   中英

How to get the selected item value from auto-suggestion plugin

I am using the jQuery mobile auto suggestion plugin. I need to get the selected value from auto suggestion list and use it into some other function.

Here is my code :

<div data-role="content">
  <ul data-role="listview" data-filter="true" id="customer">
    <li class="ui-screen-hidden" ><a href="1">BMW</a></li>
    <li class="ui-screen-hidden" ><a href="2">Mercedez</a></li>
    <li class="ui-screen-hidden" ><a href="3">Ciat</a></li>
  </ul>
</div> 
function getItem() {
  //Here i want to get the selected item from list 
  //Like value of option "BMW" is "1" I want to get that 1 value
}

You can get the clicked element by attaching and click handler and get the inner anchor href.

Code:

$(document).on("pagecreate", "#mypage", function () {
    $(document).on("click", "#customer li", function (e) {
        alert($(this).text() +" - " + $(this).find('a').attr('href'))
        e.preventDefault();
    });
});

Demo: http://jsfiddle.net/gkxgwx71/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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