如何绑定"mobileinit" jQuery Mobile中发生事件? [英] How to bind "mobileinit" event in jQuery Mobile?

查看:128
本文介绍了如何绑定"mobileinit" jQuery Mobile中发生事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这就是我试图挂接到mobileinit事件的方式:

This is how I'm trying to hook into the mobileinit event:

$(document).bind("mobileinit", function() {
    console.log("Mobile init");
});

但这不适用于Chrome(最新版本),Ripple v0.9.1和运行OS7.0的BlackBerry粗体9790.

But this doesn't work on Chrome (Latest version), Ripple v0.9.1 and on a BlackBerry bold 9790 running OS7.0.

注意:我也尝试使用.on()代替.bind(),但是没有运气.两种jQuery移动版本(1.0.1和1.1.0)均失败.

Note: I also tried using .on() instead of .bind() but no luck. Both jQuery mobile versions (1.0.1 and 1.1.0) failed.

推荐答案

我已经使用了它,并且确实有效.

I've used this and it does work.

是否有其他可能破坏脚本或未触发mobileinit?

Is it possible something else is breaking the script or the mobileinit isn't being fired?

Chrome浏览器会启动mobileinit吗?

Does Chrome fire mobileinit?

我刚刚找到了一些我在jQuery Mobile 1.0中使用过的代码,我们刚刚升级到1.1.0,并且可以正常工作.

I just found some code I used in jQuery Mobile 1.0 and we just upgraded to 1.1.0 and it works.

您要确保还包括常规的ol'jQuery,对吗?

You're making sure to also include regular ol' jQuery, right?

jQueryMobile的文档可以做到,所以我确定它可以正常工作.其他事情一定是错误的.对不起,我帮不上什么忙.您还有更多信息吗?或尝试使用其他设备.

jQueryMobile's docs do it, so I'm sure it works. Something else must be wrong. Sorry I'm not much help. Do you have any more info? Or try with a different device.

[edit] 在同一自我页面上,该消息说:由于mobileinit事件被立即触发,因此您需要在加载jQuery Mobile之前绑定事件处理程序.链接到您的JavaScript文件按以下顺序:"

[edit] On that same self page, it says "Because the mobileinit event is triggered immediately, you'll need to bind your event handler before jQuery Mobile is loaded. Link to your JavaScript files in the following order:"

<script src="jquery.js"></script>
<script src="custom-scripting.js"></script> <!-- Note your script before jqm -->
<script src="jquery-mobile.js"></script>

看起来脚本顺序可能很重要.

Looks like the script order can matter.

这篇关于如何绑定"mobileinit" jQuery Mobile中发生事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆