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