【发布时间】:2015-08-23 05:05:27
【问题描述】:
我正在使用 jqm 1.4.5。对于我的网络应用程序。在某种情况下,我在使用 pagecontainer 更改小部件以编程方式更改页面时遇到问题。我有一个主页,它是 index.html 文件的一部分。如果我通过 jqm ajax 方法从主页加载外部页面,然后从该页面有一个按钮更改回主页(通过 javascript),它会静默失败。但是,如果外部页面有一个带有 href="#home_page" 的锚按钮,它就可以工作。
JS 代码正在执行。所有的 id 都是正确的。
为什么它可以使用锚按钮而不是使用 JS 代码以编程方式使用按钮标签?
我做错了什么?
index.html
<div id="page_home" data-role="page" >
<div data-role="header">
<h1>Home Page</h1>
</div>
<div data-role="content">
<a href="page_external.html" data-role="button"> load in the external page</a>
</div>
page_external.html
<div id="page_external" data-role="page" >
<div data-role="header">
<h1>Home Page</h1>
</div>
<div data-role="content">
<a href="#page_home" data-role="button"> go to home page</a> <!-- this works -->
<button id="mybutton" data-role="button" > go to home page (script)</button> <!-- this does not work -->
</div>
JS
$(document).on("click", "#mybutton, function () {
//this fails silently and does not change the page
$(":mobile-pagecontainer").pagecontainer( "change", "#page_home" );
});
【问题讨论】:
标签: jquery-mobile