您的位置:首页 > Web前端 > JQuery

浅析jQuery Mobile的初始化事件

2015-12-03 00:00 766 查看
jQuery Mobile 包括一个初始化事件,该事件甚至会先于 jQuery 的 document.ready 事件进行加载。jQuery Mobile 实际上在文档对象本身上触发其初始化事件,第一个触发的事件是mobileinit。

当Jquery Mobile开始执行时,他就会在document对象上触发mobileinit 事件,因为mobileinit事件是在加载后马上触发,所以你需要在Jquery Mobile加载之前绑定你的事件处理函数,所以我建议你如下安排你的js引用顺序

<script src="Jquery.js"></script>
<script src="您自己的js文件"></script>
<script src="Jquery-mobile.js"></script>


要扩展 mobileinit 事件,您首先需要将它与一个自定义函数进行绑定。可使用 bind 方法扩展 mobileinit 事件,来覆盖默认配置(全局选项)。

$(document).bind("mobileinit", function(){
//覆盖的代码
});




在绑定事件的函数内部,你可以使用$.mobile对象的$.extend方法来配置默认参数值:

$(document).bind("mobileinit", function(){
 $.extend( $.mobile , {
 foo: bar
 });
});


或者单独设置它。

$(document).bind("mobileinit", function(){
 $.mobile.foo = bar;
});




$.mobile 对象是设置所有属性的起始点

<script type="text/java script" src="/scripts/jquery-1.6.min.js"></script>
<script type="text/java script">
$(document).bind("mobileinit", function(){
$.mobile.defaultTransition = "slidedown";
$.mobile.ajaxLinksEnabled = false; // 禁用Ajax提交
$.mobile.ajaxFormsEnabled = false; // 禁用Ajax提交
$.mobile.ajaxEnabled = false; //禁用Ajax提交
});
</script>
<script type="text/java script" src="/scripts/mobile/jquery.mobile-1.0b1.min.js"></script>


您可能感兴趣的文章:

jquery.mobile 共同布局遇到的问题小结
jquery mobile的触控点击事件会多次触发问题的解决方法
jQuery Mobile弹出窗、弹出层知识汇总
jQuery mobile类库使用时加载导航历史的方法简介
jQuery mobile转换url地址及获取url中目录部分的方法
使用jQuery mobile库检测url绝对地址和相对地址的方法
jquerymobile局部渲染的各种刷新方法小结
jquery mobile开发常见问题分析
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: