小提琴:http: //jsfiddle.net/ca11111/CAtWG/
如果你想在页面完全加载时做一些事情:
在你的 html 中:
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).bind("mobileinit", function(){
//$.mobile.loadingMessageTextVisible = true;
// set global config of jquery mobile here
});
</script>
<script src="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.js"></script>
<script type="text/javascript" src='test.js'></script>
然后放入你的 test.js 文件:
$("#Mypage1").live("pagecreate", function() {
//do stuff when Mypage1 is created
// happens once if you don't explicitly refresh
alert("Mypage1 created");
$("#mydiv").height($("body").height() - 50);
});
$("#Mypage1").live("pageshow", function() {
//do stuff when Mypage1 is shown
// happens multiple times, as soon as you go to Mypage1 from other pages
alert("Mypage1 visible");
});
您可能还在寻找方向更改事件,因此添加:
$(window).bind('orientationchange', _orientationHandler);
if(event.orientation){
if(event.orientation == 'portrait'){
//do something
}
else if(event.orientation == 'landscape') {
//do something
}
}
如果您触发了自己的 ajax 请求,并且想要修改 html,只需在回调中执行:
$("#Mypage1").trigger("pagecreate");