【发布时间】:2015-06-01 20:08:02
【问题描述】:
我有一个 html 页面,其中有许多 jquery 移动面板。现在我需要从 javascript 动态创建新面板。所有面板都在具有特定 ID 的 div 中。我使用 getElementById,而不是 innerHtml 在运行时附加新的 div。
问题是 jquery div 不应该出现,直到我单击打开它的链接。但是当我从 javacript 进入 jquery div 时,它显示为一个普通的 div。似乎 jquery 移动脚本无法识别我在运行时添加的新 div。 谁能帮帮我?
非常感谢。
这里有一个简单的问题示例:
<!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.2.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
</head>
<body>
<div id="panels">
<div data-role="panel" id="myPanel">
<h2>Panel Header</h2>
<p>You can close the panel by clicking outside the panel, pressing the Esc key or by swiping.</p>
</div>
</div>
<a href="#myPanel" class="ui-btn ui-btn-inline ui-corner-all ui-shadow">Open Panel</a>
<a href="#myPanel2" class="ui-btn ui-btn-inline ui-corner-all ui-shadow">Open Panel2</a>
</body>
<script type="text/javascript">
//now when an event is verified i inner the new jquery mobile panel
e.addEventListener("click", function(){
document.getElementById("panels").innerHTML+=' <div data-role="panel" id="myPanel2">
<h2>Panel Header</h2>
<p>Text</p>
</div>';
}, false);
</script>
</html>
【问题讨论】:
-
您需要post the code。另外,你能解释一下问题是什么吗?这并不容易理解。