admin管理员组文章数量:1327843
jQuery Mobile gives us these nice custom select menus where the menu es in as an overlay. I'm trying to attach an onclick function to these options but since jQuery mobile replaces the option tags with their own generated tags. I can't seem to get the function to attach to the "options" (which are actually generated as styled links).
jQuery Mobile gives us these nice custom select menus where the menu es in as an overlay. I'm trying to attach an onclick function to these options but since jQuery mobile replaces the option tags with their own generated tags. I can't seem to get the function to attach to the "options" (which are actually generated as styled links).
Share Improve this question edited May 24, 2014 at 12:28 kviiri 3,3021 gold badge23 silver badges30 bronze badges asked Dec 15, 2011 at 18:43 zareefzareef 1191 gold badge2 silver badges7 bronze badges1 Answer
Reset to default 5Rather than binding to the click
event for the "fake-option" elements, how about binding to the change
event for the <select>
element:
$('#the-select').on('change', function () {
var $this = $(this),
val = $this.val();
});
Here is a demo: http://jsfiddle/PQ39n/
Note that .on()
is new in jQuery 1.7 and in this case is the same as .bind()
.
EDIT
If you do want to bind to the click
event for the "fake-option" elements:
$('#the-page').on('click', '.ui-selectmenu-list > li', function () {
alert('onClick = ' + $('#the-select').children().eq($(this).attr('data-option-index')).val());
});
Here is a demo: http://jsfiddle/PQ39n/ (same demo as above)
In this example .on()
is the same as .delegate()
.
本文标签: javascriptFire onClick event jQuery Mobile Select MenuStack Overflow
版权声明:本文标题:javascript - Fire onClick event jQuery Mobile Select Menu - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742219299a2435149.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论