添加自定义单击事件只是辅助按钮拆分按钮列表视图jQuery Mobile的 [英] add custom click event to only secondary buttons in split button list view jquery mobile
问题描述
我目前有 ID = bookmarkslist
拆分按钮列表视图。每个里
列表是绑到每个立一个数据(项目)拆分按钮列表视图元素。我希望能写code,创建,只有当辅助按钮,拆分视图按钮,推click事件。然后,我需要能够访问的数据属性给定的里
元素( A
元素与父类= UI丽链接ALT
谁刚刚被点击我的理解有很多不同的方法来做到这一点,这是我迄今为止:
I currently have a split button list view with id=bookmarkslist
. Each li
in the list is a split button list view element with a data('item') tied to each li. I would like to be able to write code that creates a click event only when the secondary button, the split view button, is pushed. I then need to be able to access the data attribute of the given li
element (the parent of the a
element with class=ui-li-link-alt
who has just been clicked. I understand there are many different ways to do this, this is what I have so far:
$('#bookmarkslist SOMETHINGGOESHERE').live('click', function () {
alert( $(this).data('item')['url'] );
});
感谢所有帮助
推荐答案
下面是我的方式做到这一点:
Here's my way to do this:
HTML代码段:
<ul id="bookmarkslist" data-role="listview">
<li data-test="whatever1"><a href="#">test #1</a><a href="#">1.2</a></li>
<li data-test="whatever2"><a href="#">test #2</a><a href="#">2.2</a></li>
<li data-test="whatever3"><a href="#">test #3</a><a href="#">3.2</a></li>
</ul>
该JQM code:
The JQM code:
$("#bookmarkslist a.ui-li-link-alt").live("click", function(e){
alert($(this).parent("li").jqmData("test"))
});
这将提醒您在点击LI项目的数据测试属性的值。希望这有助于!
This will alert the value of your the data-test attribute on the clicked LI item. Hope this helps!
有乐趣...
这篇关于添加自定义单击事件只是辅助按钮拆分按钮列表视图jQuery Mobile的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!