JQuery Click 事件在 Mobile Safari 中的下一次单击时重复
我正在为客户开发一个 HTML5 应用程序,供他们在 iPad 平台上内部使用。为各种任务实现各种 JQUERY 解决方案的一切都进展顺利,但这个解决方案似乎没有意义。
他们在页面上有一个项目列表,包含在一个无序列表中,他们希望用户能够拖放该列表来重新排列顺序,或者单击删除按钮来删除其中一个项目。
一开始我把它排序得很好,删除也很好。但是,当在 iPad 上测试时,在我单击删除按钮后,它会运行确认并执行我定义的操作。但是,下次我单击屏幕时,即使我距离定义为触发此事件的 div 很远,也会再次触发单击事件。
之一的 HTML 片段
比较
- 竞争对手:[品牌]
- 我们:[品牌]
(×);
[经销商]
以下是完成这些任务的各种 jquery 包含和内部 javascript:
<script src="../../js/libs/jquery.min.js" type="text/javascript"></script>
<script src="../../js/libs/jquery-ui.min.js" type="text/javascript"></script>
<script src="../../js/libs/jquery.ui.touch-punch.min.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
$(function () {
$(".remove").click(function () {
var e = $(this);
this.style.backgroundColor = "#FFAAAA";
var p = this.parentNode;
var count = 1;
while (p.tagName != 'LI') {
p = p.parentNode;
count++;
}
var cont = confirm("Are you sure you would like to delete this item?");
if (cont) {
var deletedItems = document.getElementById('deletedItems');
if (deletedItems.value != "") {
deletedItems.value += ",";
}
deletedItems.value += p.id;
p.style.display = 'none';
}
this.style.backgroundColor = "transparent";
});
$("#sortable").sortable({
stop: function (event, ui) {
var newOrder = "";
for (i = 0; i < $("#sortable li").size(); i++) {
newOrder += $("#sortable li").get(i).id;
if (i < $("#sortable li").size() - 1) {
newOrder += ",";
}
}
document.getElementById('currentOrder').value = newOrder;
}
});
$("#sortable").disableSelection();
});
</script>
I am developing an HTML5 application for a client for their internal use on the iPad platform. Everything has been going very well implementing various JQUERY solutions for a variety of tasks, but this one just doesn't seem to make sense.
They have a list of items on a page, contained in an un-ordered list, which they would like their users to be able to drag and drop to shuffle the order, or click a delete button to remove one of the items.
I have it sorting just fine and it deletes just fine, at first. But then, when testing on the iPad, after I have clicked on the delete button, it runs through a confirm and performs the operation I have defined. But then, the next time I click on the screen in triggers the click event again, even if I am far away from the div which is defined to trigger this event.
Here is an HTML snippet of one of the
<li id="12345">
<div class="clearfix">
<div class="product-image">
<img src="../../img/presentation.png" width="200" height="140" />
</div>
<div class="product-info">
<div class="details">
<h3><a class="name" href="#">Comparison</a></h3>
<ul>
<li><strong>Competitor: </strong>[Brand]</li>
<li><strong>Us: </strong>[Brand]</li>
</ul>
</div>
<div class="brand">
<div class="remove" style="width: 30px; height: 30px;">(×)</div>
<div class="edit-bar"><img src="../../img/presentations-edit-bars.png" /></div>
<p class="logo">[Distributor]</p>
</div>
</div>
</div>
Here are the various jquery includes and the internal javascript to accomplish these tasks:
<script src="../../js/libs/jquery.min.js" type="text/javascript"></script>
<script src="../../js/libs/jquery-ui.min.js" type="text/javascript"></script>
<script src="../../js/libs/jquery.ui.touch-punch.min.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
$(function () {
$(".remove").click(function () {
var e = $(this);
this.style.backgroundColor = "#FFAAAA";
var p = this.parentNode;
var count = 1;
while (p.tagName != 'LI') {
p = p.parentNode;
count++;
}
var cont = confirm("Are you sure you would like to delete this item?");
if (cont) {
var deletedItems = document.getElementById('deletedItems');
if (deletedItems.value != "") {
deletedItems.value += ",";
}
deletedItems.value += p.id;
p.style.display = 'none';
}
this.style.backgroundColor = "transparent";
});
$("#sortable").sortable({
stop: function (event, ui) {
var newOrder = "";
for (i = 0; i < $("#sortable li").size(); i++) {
newOrder += $("#sortable li").get(i).id;
if (i < $("#sortable li").size() - 1) {
newOrder += ",";
}
}
document.getElementById('currentOrder').value = newOrder;
}
});
$("#sortable").disableSelection();
});
</script>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这似乎是许多人面临的共同问题。可能的原因是,在 iPad 上,您有两个事件被称为点击和单击。
解决方案是在处理实际事件之前解除事件绑定,
希望这有效。
This seems to be somewhat of a common issue faced by many people. The probable reason is that on the iPad, you have two events getting called tap and click.
The solution would be to unbind your events before handling the actual event like
Hope this works.