我有以下代码,很明显JQuery正在运行,但是一些JQuery Mobile事件根本没有触发:
<!DOCTYPE html>
<html>
<head>
<title>JQuery Mobile Test</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="js/jquery.js"></script>
<script src="js/jquery.mobile.custom.complete.min.js"></script>
<link rel="stylesheet" href="css/jquery.mobile.custom.complete.theme.min.css"/>
<link rel="stylesheet" href="css/jquery.mobile.custom.complete.structure.min.css"/>
<script>
$(function(){
$(document).on("touchstart", function(e){
$('#touchstart').html("touchstart");
});
$(document).on("touchend", function(e){
$('#touchend').html("touchend");
});
$(document).on("touchmove", function(e){
$('#touchmove').html("touchmove");
});
$(document).on("touchcancel", function(e){
$('#touchcancel').html("touchcancel");
});
$(document).on("tap", function(e){
$('#tap').html("tap");
});
$(document).on("taphold", function(e){
$('#taphold').html("taphold");
});
$(document).on("swipe", function(e){
$('#swipe').html("swipe");
});
});
</script>
<style>
</style>
</head>
<body>
<div id="touchstart">-</div>
<div id="touchend">-</div>
<div id="touchmove">-</div>
<div id="touchcancel">-</div>
<div id="tap">-</div>
<div id="taphold">-</div>
<div id="swipe">-</div>
</body>
</html>
我在Android上的Chrome上试用了它。在上述事件中,这些事件不起作用:tap
,taphold
和swipe
。我已经对文件网址进行了三次检查。
上面的JQuery版本:JQuery:压缩,生产3.1.1,以及最新的JQuery Mobile:1.4.5,自定义所有选项,缩小。
当我用JQuery托管的(随机)早期版本替换链接和脚本标记时,恼人地它可以正常工作:
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css" />
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.js"></script>
当我使用最新的JQuery托管版本时无效:
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css" />
<script src="http://code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
但我需要自己托管文件,我想拥有最新版本。我究竟做错了什么? API有差异吗?或者它是一个JQuery错误?
答案 0 :(得分:3)
扩展Omar上面的评论...... jQuery Mobile现在与最新版本的jQuery不兼容。如果您查看jquerymobile homepage,您将在下载按钮(右上角)下看到您可以使用的jQuery版本。目前,对于jQM v.1.4.5,您需要:
jQuery 1.8 - 1.11 / 2.1