add custom click event to only secondary buttons in split button list view jquery mobile

瘦欲@ 提交于 2019-12-12 02:12:03

问题


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'] );
});

Thanks for all the help


回答1:


Here's my way to do this:

The HTML snippet:

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

The JQM code:

$("#bookmarkslist a.ui-li-link-alt").live("click", function(e){
      alert($(this).parent("li").jqmData("test")) 
});

This will alert the value of your the data-test attribute on the clicked LI item. Hope this helps!

Have fun...



来源:https://stackoverflow.com/questions/8222965/add-custom-click-event-to-only-secondary-buttons-in-split-button-list-view-jquer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!