查看工作示例:finished == true和finished == false:单击按钮,看看会发生什么......
1)finished == true
:弹出窗口自动打开
2)finished == false
:我曾经return false
阻止打开弹出窗口
脚本:
$(document).bind('pageinit', function() {
$("#mytest").click(function() {
var finished = false;
// RUN MY FUNCTION AND THEN IF TRUE RUN POPUP (WILL OPEN AUTOMATICALLY)
if(finished == false){
// PREVENT OPENING POPUP
return false;
}
});
});
完整的例子:
<html>
<head>
<meta charset="utf-8">
<title>popup</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
</head>
<body>
<div data-role="page" id="myPage">
<div data-role="content">
<h1>Popup</h1>
<a style="height: 75px;" href="#eat" data-rel="popup" data-role="button" id="mytest">Test</a>
</div>
<section data-role="popup" data-overlay-theme="a" id="eat">
Are you sure you want to eat?
</section>
<script>
$(document).bind('pageinit', function() {
$("#mytest").click(function() {
var finished = false;
// RUN MY FUNCTION AND THEN IF TRUE RUN POPUP (WILL OPEN AUTOMATICALLY)
if(finished == false){
// PREVENT OPENING POPUP
return false;
}
});
});
</script>
</div>
</body>
</html>