jQuery Mobile页面跳转后未加载外部JS原因分析及解决
来源:互联网 发布:网站用linux还是win 编辑:程序博客网 时间:2024/06/15 18:41
jQuery Mobile页面跳转后未加载外部JS原因分析及解决
在使用jQuery Mobile进行Web开发中,当页面跳转时(pageA => pageB),pageB上面的JS事件都没有起到作用,在pageB中引用的JS并未成功运行。因为,JQM并为将整个页面加载到当前的dom中,仅将data-role="page"元素加入当前的dom中。
因此,在<head>中引入的外部JS文件,以及<page>标签外的JS均不能正常运行,刷新页面后方可加载成功。
鉴于JQM这个特性不太可能主动更改,可以用两种方法来解决:
一是在index页面中,注册所有需要使用到的外部JS文件,或者使用母版页面来统一;
二是将页面内部JS写在data-role="page"标签下,这样无论页面怎样跳转,均可以运行。
例子:A网页转跳到B网页,自动弹出正在加载的事件
A网页
<!DOCTYPE html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><link rel="stylesheet" href="https://apps.bdimg.com/libs/jquerymobile/1.4.5/jquery.mobile-1.4.5.min.css"><script src="https://apps.bdimg.com/libs/jquery/1.10.2/jquery.min.js"></script><script src="https://apps.bdimg.com/libs/jquerymobile/1.4.5/jquery.mobile-1.4.5.min.js"></script></head><body><div data-role="page" id="pageone"> <div data-role="header"> <h1>页眉文本</h1> </div> <div data-role="main" class="ui-content"> <p>页面一</p> <a href="04.php">转到页面二</a> </div> <div data-role="footer"> <h1>页脚文本</h1> </div></div> </body></html>
<!DOCTYPE html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><link rel="stylesheet" href="https://apps.bdimg.com/libs/jquerymobile/1.4.5/jquery.mobile-1.4.5.min.css"><script src="https://apps.bdimg.com/libs/jquery/1.10.2/jquery.min.js"></script><script src="https://apps.bdimg.com/libs/jquerymobile/1.4.5/jquery.mobile-1.4.5.min.js"></script></head><body><div data-role="page" id="pagetwo"> <script> // setTimeout('showLoader()', 100);//这里要延迟一下,直接调用无法显示加载器 //显示加载器.for jQuery Mobile 1.2.0 function showLoader() { $.mobile.loading('show', { text: '正在保存中...', //加载器中显示的文字 textVisible: true, //是否显示文字 theme: 'a', //加载器主题样式a-e textonly: false, //是否只显示文字 html: "" //要显示的html内容,如图片等 }); }//隐藏加载器.for jQuery Mobile 1.2.0 function hideLoader() {$.mobile.loading('hide');}</script><script> $(document).on("pageshow",function(){ showLoader();//自动弹出加载中的层}); </script> <div data-role="header"> <h1>页眉文本</h1> </div> <div data-role="main" class="ui-content"> <!--这里是PHP中弹出--> <?php echo "<script>$(document).on('pageshow',function(){showLoader();});</script>"?> <p>页面二</p> </div> <div data-role="footer"> <h1>页脚文本</h1> </div></div> </body></html>
0 0
- jQuery Mobile页面跳转后未加载外部JS原因分析及解决
- jQuery Mobile页面跳转后未加载外部JS原因分析及解决
- jQuery Mobile页面跳转后未加载外部JS
- jQuery Mobile页面跳转后未加载外部JS
- jQuery Mobile页面跳转后未加载JS解决办法
- jQuery Mobile页面跳转后,无法加载js中的方法
- jQuery Mobile页面跳转导致css、js失效原因及解决方法
- jquery mobile页面跳转 js无法加载的解决办法
- jquery mobile页面跳转后样式丢失js失效
- jquery mobile页面跳转后js不执行的问题
- jquery mobile页面跳转后样式丢失js失效
- JQuery Mobile跳转页面后css和js失效
- dedecms header文章 跳转属性打开后页面空白原因分析及解决
- jquery mobile页面跳转后,必须重新刷新页面js方可有效
- jquery mobile页面跳转后,必须重新刷新页面js方可有效
- jQuery Mobile页面加载机制及页面跳转出现的问题
- spring jquery Mobile 页面跳转后浏览器url未改变&&javaScript代码刷新后才能执行的问题解决
- jquery mobile开发中页面跳转后js不执行的问题
- Linux驱动开发(五)——中断和时钟
- Android 集成二维码扫描器
- oj-15-L-字符串的替换
- 在线社交网络中异常帐号检测方法研究
- Linux驱动开发(六)——内存使用
- jQuery Mobile页面跳转后未加载外部JS原因分析及解决
- squid range请求处理解析
- NOR型flash与NAND型flash的区别
- redis 持久化
- Linux驱动开发(七)——设备驱动模型
- 【Unity】关于精灵物体创建的看法
- C语言数据结构之哈夫曼树及其应用
- 学习CSS你必须踩得那些坑(二)
- UnsatisfiedLinkError: Error looking up function 'TessBaseAPICreate': /usr/lib/lib2.so.3.0.2: