[英]onload not working after i use $.mobile.changePage
I will change page by $.mobile.changePage with code 我将使用代码通过$ .mobile.changePage更改页面
$.mobile.changePage("profile.html", { transition : "slide"},false);
topage profile.html code topage profile.html代码
<html>
<head>
<script type="text/javascript">
function func()
{
document.getElementById("d").innerHTML="String"
}
</script>
</head>
<body onload="func()">
<div id="d"></div>
</body>
</html>
javascript code JavaScript代码
function func()
{
document.getElementById("d").innerHTML="String"
}
not work ,How to resolve? 不起作用,如何解决?
If you take a look at the documentation , the reloadPage
option is initially false which means that the page will not be reloaded, hence the onload
event of the current document won't be fired again. 如果您查看文档 ,则
reloadPage
选项最初为false,这意味着将不会重新加载该页面,因此不会再次触发当前文档的onload
事件。
To make your body onload
event to work again, you will need to add this option and set its value to true
: 为了使您的body
onload
事件再次起作用,您需要添加此选项并将其值设置为true
:
var options={
transition: "slide",
reloadPage: true
};
$.mobile.changePage("profile.html", options, false);
jQuery Mobile uses Ajax to load pages. jQuery Mobile使用Ajax加载页面。 When first page is loaded, all tags and codes inside
<html>
are loaded. 加载第一页时,将加载
<html>
中的所有标记和代码。 However, when you change page or load another html file, it loads only first page div data-role=page
neglecting all tags and js outisde that div. 但是,当您更改页面或加载另一个html文件时,它仅加载首页div
data-role=page
忽略了所有标记,而js超出了该div。
If you have any extra JS code, place it inside page div data-role="page"
. 如果您有任何其他JS代码,请将其放在page div
data-role="page"
。
<div data-role="page">
<script>
document.getElementById("d").innerHTML="String"
</script>
</div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.