以下jQuery代码将执行每个" pagecreate"但我只读过"我来自foo down bar。"我从来没有读过"河流foo和bar thunder!"。我可以向你保证,我的标记有很多分区标记。
$(document).on("pagecreate", "#index", function () {
alert("I come from the foo down bar.");
$("div").on("tap", function () {
alert("Where rivers foo and bar thunder!");
$(this).hide();
});
});
以下是失败页面的简化示例:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>
</title><link href="/Content/jquery.mobile-1.4.2.css" rel="stylesheet"/>
<link href="/Content/jquery.mobile.theme-1.4.2.css" rel="stylesheet"/>
<link href="/Content/jquery.mobile.structure-1.4.2.css" rel="stylesheet"/>
<link href="/Content/themes/mobile.css" rel="stylesheet"/>
<link href="/Content/themes/jquery.mobile.icons.min.css" rel="stylesheet"/>
<link href="/Content/Mobile/Site.css" rel="stylesheet"/>
<link href="/Scripts/jquery-2.1.0.js" rel="stylesheet"/>
<link href="/Scripts/Mobile/Warning.js" rel="stylesheet"/>
<link href="/Scripts/jquery.mobile-1.4.2.js" rel="stylesheet"/>
</head>
<body>
<form method="post" action="DefaultISH.aspx" id="form1">
<div class="aspNetHidden">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="VHiLIso4vJwEKglDsP400Owtzfidxc4g1kzhU450G4jeIhwpxe/oiIWD8Tv7WzOAgPDpiSp229wXt2ML2qVRUPcH+Vh/Do2FlIV7M5yxYug=" />
</div>
<div id="index" data-role="page">
<p>Dos eat oats.</p>
</div>
</form>
<script>
$(document).on("pagecreate", "#index", function () {
alert("I come from the foo down bar.");
$(document).on("tap click vclick", "p", function () {
alert("Where rivers foo and bar thunder!");
$(this).hide();
});
});
</script>
<!-- Visual Studio Browser Link -->
<script type="application/json" id="__browserLink_initializationData">
{"appName":"Firefox","requestId":"7a541c555bc144bd927e24c1375eea63"}
</script>
<script type="text/javascript" src="http://localhost:50293/91b671a7150345b7859822835d8e2556/browserLink" async="async"></script>
<!-- End Browser Link -->
</body>
</html>
有关JSFiddle
上问题的示例对于我希望实施的工作example。
答案 0 :(得分:1)
做一点点不同,而不是直接将它绑定到div,将它绑定到文档级别,让它传播do和div元素,如下所示:
$(document).on("pagecreate", "#index", function () {
alert("I come from the foo down bar.");
$(document).on("tap click vclick", "div",function () {
alert("Where rivers foo and bar thunder!");
$(this).hide();
});
});
工作示例:http://jsfiddle.net/Gajotres/M82UZ/
最后一点点击不适用于所有桌面浏览器(Firefox),因此使用 vclick 而不是点按,这是一个jQuery Mobile解决方案,可以跨浏览器点击支持。
答案 1 :(得分:0)
$(document).on("pagecreate", "#index", function () {
alert("I come from the foo down bar.");
$("div").bind("tap", function () {
alert("Where rivers foo and bar thunder!");
$(this).hide();
});
});
更改为绑定
$(document).on("pagecreate", "#index", function () {
alert("I come from the foo down bar.");
$("div").on("click", function () {
alert("Where rivers foo and bar thunder!");
$(this).hide();
});
});
更改绑定以单击
$(document).ready(function(){
alert("I come from the foo down bar.");
$("div").on("click", function () {
alert("Where rivers foo and bar thunder!");
$(this).hide();
});
});
答案 2 :(得分:-1)
问题比想象的要大。 jQuery Mobile的版本不正确或版本存在冲突。问题是我最终安装了不兼容的NuGet包。