jQuery移动重复事件 [英] jQuery mobile duplicated events
问题描述
这是一个让我疯狂的新手问题。根据 jQuery手机网站,我已经包含了 jQuery 和 jQuery mobile 到HTML的头
。
This is a newbie question that is driving me crazy. According to jQuery mobile site, I have included jQuery and jQuery mobile into the head
of the HTML.
然后,当我为任何事件分配listeneres时,它是跑两次示例:
Then, when I am assigning listeneres for any event, it's running twice. Example:
<!doctype html>
<html>
<head>
<meta http-equiv="imagetoolbar" content="false" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<style>
.slide {width:400px; height:400px; padding:40px; border:1px solid black;}
</style>
<link href="http://code.jquery.com/mobile/latest/jquery.mobile.min.css" rel="stylesheet" type="text/css" />
<script src="http://code.jquery.com/jquery-1.6.2.min.js"></script>
<script src="http://code.jquery.com/mobile/latest/jquery.mobile.min.js"></script>
</head>
<body>
<div class="slide">
<h1>1</h1>
</div>
<script type="text/javascript">
$(function() {
$('.slide').tap(function() {
alert('tapped!');
});
});
</script>
</body>
</html>
然后,如果我点击(或在桌面浏览器中)滑动div,两个警报显示。如果我评论的行包括jQuery mobile,它只运行一次。
Then, if I tap (or click in a desktop browser) that slide div, two alerts are shown. If I comment the line including jQuery mobile, it only runs once.
这里有什么关系?
推荐答案
如果你移动您的脚本进入< head>
标签,它只会启动一次。我认为这是与疯狂的jQuery Mobile页面缓存有关。
If you move your script into <head>
tag, it will only fire once. I think it's something to do with crazy jQuery Mobile page caching.
这篇关于jQuery移动重复事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!