在使用jQuery Mobile进行Web开发中,当页面跳转时(pageA => pageB),在pageB中引用的JS并未成功运行。因为,JQM使用的是ajax跳转,JQM并未将整个页面加载到当前的dom中,它仅将data-role="page"元素加入当前的dom中。
因此,在<head>中引入的外部JS文件,以及<page>标签外的JS均不能正常运行,刷新页面后方可加载成功。
解决办法:
1:将页面内部JS在data-role="page"标签下引用,这样无论页面怎样跳转,均可以运行。
2:在a标签中添加data-ajax="fase"或者rel="external"属性。如下
<div data-role="header" data-theme="b">
<div data-role="navbar">
<ul>
<li><a href="/about_us.htm" target="_blank" rel="external nofollow" rel="external" >About Us</a></li>
</ul>
</div>
</div>