##使用jquery mobile popup功能時遇到這問題
###我的程式碼
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<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-1.11.3.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
<script>
$('document').ready(function(){
var element='<a href="#secondPop" data-rel="popup" class="ui-btn ui-btn-inline ui-corner-all">The Add Popup</a><div data-role="popup" id="secondPop"><p>This is a second popup.</p></div>'
$("#list").append('<li>'+element+'</li>');
$("#list").listview('refresh');
})
</script>
</head>
<body>
<div data-role="page">
<div data-role="header">
<h1>Welcome To My Homepage</h1>
</div>
<div data-role="main" class="ui-content">
<ul data-role="listview" id="list">
<li>
<a href="#myPopup" data-rel="popup" class="ui-btn ui-btn-inline ui-corner-all">Offical Demo Popup</a>
<div data-role="popup" id="myPopup">
<p>This is a simple popup.</p>
</div>
</li>
</ul>
</div>
<div data-role="footer">
<h1>Footer Text</h1>
</div>
</div>
</body>
</html>
###其中可看到第二個The Add Popup 原本要跳出視窗的div文字"This is a second popup."
並沒有被隱藏
####我嘗試過加入官方demo文件中的語法
<script id="popup-arrow-script">
$.mobile.document.on( "click", "#open-popupArrow", function( evt ) {
$( "#popupArrow" ).popup( "open", { x: evt.pageX, y: evt.pageY } );
evt.preventDefault();
});
</script>
<style id="popup-arrow-css">
.clickable-area {
display: block;
width: 100%;
height: 300px;
background-color: #ffefef;
}
.clickable-area:focus {
outline: 0;
}
</style>
<style id="tooltip-btn">
.ui-btn.my-tooltip-btn,
.ui-btn.my-tooltip-btn:hover,
.ui-btn.my-tooltip-btn:active {
background: none;
border: 0;
}
</style>
####首先是它會不認得open這個指令,再來是要動態新增的元素有很多列.請問我是否有漏掉什麼,或是有何解決方法.
請參考:https://demos.jquerymobile.com/1.4.5/popup-dynamic/
$('document').ready(function(){
var listElement=$(`<li><a
href="#secondPop"
data-rel="popup"
class="ui-btn ui-btn-inline ui-corner-all"
>The Add Popup</a></li>`);
$("#list").append(listElement);
$("#list").listview('refresh');
listElement.click(function(){
var popup=$(`<div
data-role="popup"
id="secondPop"
><p>This is a second popup.</p>
</div>`).on('afterclose', function(){
$(this).remove();
});
popup.appendTo(listElement).popup();
});
})
要點大概就是: