本文介绍了如何获取触发了Taphold的元素(jQuery Mobile)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
能否请我通过使用js,jquery或jq mobile来确定在哪个元素"taphold"上触发.我的html结构如下所示
Can you please help me to locate on which element "taphold" is fired by using js, jquery or jq mobile.my html structure is like mentioned below
<script>
$(document).on("pagecreate", function () {
$("#myFilesListView").bind('contextmenu', function (event) {
event.preventDefault();
event.stopPropagation();
return false;
});
});
$(document).ready(function () {
$("#myFilesListView").bind("taphold", function (event) {
event.preventDefault(false);
event.stopPropagation();
var ID = $(this).child().attr("id");
alert(ID);
});
});
</script>
<div data-role="page" id="page1">
<div data-role="header"></div>
<div data-role="main">
<ul data-role="listview" id="mylistview">
<li class="mydata" id="1"> some conetent</li>
<li class="mydata" id="2"> some conetent</li>
<li class="mydata" id="3"> some conetent</li>
<li class="mydata" id="4"> some conetent</li>
<li class="mydata" id="5"> some conetent</li>
<!--ids are not in predefined sequences and there may be 100s of list-->
</ul>
</div>
<div data-role="fotter"></div>
</div>
在我的javascript代码中,我能够防止taphold的默认行为,但是当用户点击并按住该列表时,我就无法立即获取特定列表的ID.
in my javascript code I am able to prevent the default behavior of taphold, but I am not getting how to get the Id of a particular list as soon as a user tap and hold on that list.
推荐答案
您可以将Taphold绑定到li元素而不是listview:
You can bind the taphold to the li elements instead of the listview:
$(document).on("pagecreate", "#page1", function () {
$("#mylistview").on('contextmenu', function (event) {
event.preventDefault();
event.stopPropagation();
return false;
});
$("#mylistview li").on("taphold", function (event) {
var ID = $(this).prop("id");
alert(ID);
});
});
这篇关于如何获取触发了Taphold的元素(jQuery Mobile)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!