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

查看:12
本文介绍了如何绑定“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 bold 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.

推荐答案

我用过这个,它确实有效.

是否有其他原因破坏了脚本或没有触发 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] 在同一个 self 页面上,它说因为 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天全站免登陆