当您有两个带有弹出窗口的页面时,事情似乎很奇怪。
我创建了这个简单的示例来演示我所看到的
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.3/jquery.mobile-1.4.3.min.css">
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.3/jquery.mobile-1.4.3.min.js"></script>
<script src="libs/jquery.mobile.paramsHandler-1.4.2.js"></script>
<script src="clickdemo.js"></script>
<style>
.thumbnail
{
float: left;
width: 80px;
border: 1px solid #999;
margin: 0 15px 15px 0;
padding: 5px;
text-align:center;
}
.thumbnail img
{
width: 80px;
height: 80px;
}
</style>
</head>
<body>
<div data-role="page" id="Home">
<div data-role="main" class="ui-content">
<a href="#workingPage" class="ui-btn">Working Page</a>
<a href="#brokenPage" class="ui-btn">Broken Page</a>
</div>
</div>
<div data-role="page" id="workingPage">
<div data-role="popup" id="workingImagePopup" data-overlay-theme="b" data-theme="b" data-corners="false">
<a href="#" data-rel="back" class="ui-btn ui-corner-all ui-shadow ui-btn-a ui-icon-delete ui-btn-icon-notext ui-btn-right">Close</a>
<img id="WorkingPopUpPhoto" class="PopPhoto" src="" alt="">
</div>
<div data-role="main" class="ui-content">
<div class="thumbcontainer">
<div class="thumbnail">
<img src="http://www.funnypica.com/wp-content/uploads/2012/05/Funny-UglyMan.jpg" alt="" ><br>
</div>
<div class="thumbnail">
<img src="http://www.funnypica.com/wp-content/uploads/2012/05/Crazy-Face-570x403.jpg" alt="" ><br>
</div>
</div>
</div>
</div>
<div data-role="page" id="brokenPage">
<div data-role="popup" id="brokenImagePopup" data-overlay-theme="b" data-theme="b" data-corners="false">
<a href="#" data-rel="back" class="ui-btn ui-corner-all ui-shadow ui-btn-a ui-icon-delete ui-btn-icon-notext ui-btn-right">Close</a>
<img id="brokenPopUpPhoto" class="PopPhoto" src="" alt="">
</div>
<div data-role="main" class="ui-content">
<div class="thumbcontainer">
<div class="thumbnail">
<img src="http://www.funnypica.com/wp-content/uploads/2012/05/Funny-UglyMan.jpg" alt="" ><br>
</div>
<div class="thumbnail">
<img src="http://www.funnypica.com/wp-content/uploads/2012/05/Crazy-Face-570x403.jpg" alt="" ><br>
</div>
</div>
</div>
</div>
</body>
</html>
我用这个 JS 支持那个代码
$(document).on("pagecreate", "#workingPage", function () {
$(".thumbnail img").click(function (e) {
alert("clicked");
var thumbnailPath = $(this).attr("src");
$('#WorkingPopUpPhoto').attr("src",thumbnailPath); //set the image source of the popup
$('#workingImagePopup').popup('open'); //open the popup
});
});
$(document).on("pagecreate", "#brokenPage", function () {
$(".thumbnail img").click(function (e) {
alert("clicked");
var thumbnailPath = $(this).attr("src");
$('#brokenPopUpPhoto').attr("src",thumbnailPath); //set the image source of the popup
$('#brokenImagePopup').popup('open'); //open the popup
});
});
由于两个页面非常相似(剪切和粘贴,仅更改了 ID),因此我希望它们的工作方式相同。如果单击图像,您将看到一个警报,然后是弹出图像。预计这两个页面是相同的。单击图像,查看警报,然后是弹出窗口。
这是我正在经历的。
我访问了工作页面(从家开始并导航到“工作页面”),一切都按预期工作。单击缩略图会显示警报和弹出图像。
然后我在浏览器中单击返回,将我带到主页,单击“损坏的页面”(“工作页面”的副本)并且行为不同。单击图像时,首先您会看到两个警报(为什么?),然后不会显示弹出图像。
II 重新加载并颠倒顺序(即:从“破碎的页面”开始)出现相同的模式,破碎的页面有效,工作页面现在破碎(暗示它不是标记或JS)
难道我做错了什么?