在 ajax 导航页面中,用于执行初始化 javascript 的经典“文档就绪”表单根本不会触发。
在 ajax 加载的页面中执行一些代码的正确方法是什么?
(我的意思是,不是我的 ajax ......它是 jquery 移动页面导航系统,它把我带到了那个页面)
好吧,我确实怀疑这样的事情......非常感谢 =) 但是......它仍然不起作用,这是我的代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>mypage</title>
<link rel="stylesheet" href="jquery.mobile-1.0a4.min.css" />
<script type="text/javascript" src="jquery-1.5.min.js"></script>
<script type="text/javascript" src="jquery.mobile-1.0a4.min.js"></script>
<script type="text/javascript">
$('div').live('pageshow',function(event, ui){
alert('ciao');
});
</script>
</head>
<body>
<div data-role="page">
<div data-role="header" data-position="fixed">
<h1>Shopping Cart</h1>
</div>
<div data-role="content"> asd
</div>
</div>
</body>
我需要指定 div id 吗?
最佳答案
我花了一些时间研究相同的内容,因为此时 JQM 文档还不是很详细。下面的解决方案对我来说很好用:
<script type="text/javascript">
$('div:jqmData(role="page")').live('pagebeforeshow',function(){
// code to execute on each page change
});
</script>
您必须实现自己的检查流程以防止多次初始化,因为上面的代码将在每次页面更改时运行
关于ajax - jQuery mobile $(document).ready 等价物,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5622581/