我试图在JQuery手机上创建一个应用程序,在这个应用程序中,我可以用弹出窗口动态地创建按钮。我有这段代码,但是每当我刷新页面时,它就会在屏幕顶部自动打开,而不是所有其他弹出窗口。
$(document).on("pageinit", "#home", function() {
$(".img-holder").append(
$("<div />", {"class" : "spot_holder"}).append(
$("<a />", {
"href" : "#ashcloud",
"data-rel" : "popup",
"class" : "spot ui-btn ui-nodisc-icon ui-btn-icon-notext ui-corner-all",
"data-transition" : "flip",
"style" : "top: 35px; left: 240px"
})
).append(
$("<div />", {
"data-role" : "popup",
"id" : "ashcloud"
}).append(
$("<p />").text("Ash Cloud")
).popup()
)
)
})<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="js/jQueryMobile/jquery.mobile-1.4.5.css">
<link rel="stylesheet" href="styles.css">
<script src="js/jQueryMobile/jquery-1.11.3.min.js"></script>
<script src="js/jQueryMobile/jquery.mobile-1.4.5.js"></script>
<script src="js/script.js"></script>
</head>
<body>
<div data-role="page" id="home">
<div class="ui-content">
<div class="img-holder">
<img src="img/volcano.jpg" class="image" width="500px">
<!--
<div class="spot-holder">
<a href="#ashcloud"
data-rel="popup"
class="spot ui-btn ui-nodisc-icon ui-btn-icon-notext ui-corner-all"
data-transition="flip"
style="top: 35px; left: 240px;"></a>
<div data-role="popup" id="ashcloud">
<p>Ash Cloud</p>
</div>
</div>
-->
<div class="spot-holder">
<a href="#mainpipe"
data-rel="popup"
class="spot ui-btn ui-nodisc-icon ui-btn-icon-notext ui-corner-all"
data-transition="flip"
style="top: 250px; left: 232px;"></a>
<div data-role="popup" id="mainpipe">
<p>Main Pipe</p>
</div>
</div>
<div class="spot-holder">
<a href="#sidevent"
data-rel="popup"
class="spot ui-btn ui-nodisc-icon ui-btn-icon-notext ui-corner-all"
data-transition="flip"
style="top: 180px; left: 210px"></a>
<div data-role="popup" id="sidevent">
<p>Side Vent</p>
</div>
</div>
<div class="spot-holder">
<a href="#lavaflow"
data-rel="popup"
class="spot ui-btn ui-nodisc-icon ui-btn-icon-notext ui-corner-all"
data-transition="flip"
style="top: 120px; left: 215px"></a>
<div data-role="popup" id="lavaflow">
<p>Lava Flow</p>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
发布于 2015-10-20 19:35:35
算了,我找到了解决办法。而不是为每个按钮创建一个弹出窗口,而是在所有按钮之间创建一个单独的弹出窗口,然后通过JS,每次单击它时都更改弹出窗口中的文本。
发布于 2015-10-19 05:10:13
看起来,您正在尝试以纯jQuery方式创建对话,而不是jQuery移动。
下面是如何创建jQuery移动对话的示例。注意,这里没有Javascript代码。您所需要的只是创建带有data-dialog="true"属性的页面,并从主页链接它。
<!--...-->
<!-- page Help -->
<div data-role="page" id="help" data-theme="b">
<!-- header (same data-id for persistent toolbar) -->
<div data-role="header" data-id="tabnav-header" data-position="fixed"
data-theme="b">
<h1>MyApp</h1>
</div>
<!-- content -->
<div data-role="content" class="content_div">
<ul data-role="listview">
<li><a href="#about" data-transition="flip">About</a></li>
</ul>
</div>
<!-- footer -->
<div data-role="footer" data-id="tabnav-footer" data-position="fixed">
<div data-role="navbar">
<ul>
<li><a href="#home" data-theme="b" style="font-weight: normal;" data-icon="home" data-transition="slide">Home</a></li>
<li><a href="#help" data-theme="b" class="ui-btn-active ui-state-persist" style="font-weight: normal;" data-icon="bars" data-transition="slide">Help</a></li>
</ul>
</div>
</div>
</div>
<!-- This page is actually a dialogue window -->
<div data-role="page" data-dialog="true" id="about" data-theme="b">
<div data-role="header" data-theme="b">
<h1>About</h1>
</div>
<div data-role="main" class="ui-content" data-theme="b">
MyApp. All rights deserved.
</div>
<div data-role="footer" data-theme="b"></div>
</div>
...发布于 2015-10-21 07:38:04
在JQ手机上有一个如何动态创建弹出的例子。http://demos.jquerymobile.com/1.4.1/popup-dynamic/
首先,它们附加在页面事件上,而不是"pageinit“。其次,我认为这就是诀窍,他们在追加后称之为“触发器”(“分页”)。
$.mobile.activePage.append( popup ).trigger( "pagecreate" );https://stackoverflow.com/questions/33199984
复制相似问题