當你有兩個彈出頁面的東西似乎奇怪的工作。jquery移動彈出窗口stra 012作用
我創造了這個簡單的例子來證明我所看到的
<!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)
我做錯了什麼?
http://jsfiddle.net/Palestinian/huc1ubs6/ – Omar 2014-11-17 09:42:53