Javascript 如何绑定";mobileinit“;jQuery Mobile中的事件?

Javascript 如何绑定";mobileinit“;jQuery Mobile中的事件?,javascript,jquery-mobile,Javascript,Jquery Mobile,这就是我试图与mobileinit事件挂钩的方式: $(document).bind("mobileinit", function() { console.log("Mobile init"); }); 但这在Chrome(最新版本)、Ripple v0.9.1和运行OS7.0的BlackBerry bold 9790上不起作用 注意:我还尝试使用.on()而不是.bind(),但没有成功。jQuery移动版(1.0.1和1.1.0)都失败了。我用过这个,它确实可以工作 有没有可能是别

这就是我试图与mobileinit事件挂钩的方式:

$(document).bind("mobileinit", function() {
    console.log("Mobile init");
});
但这在Chrome(最新版本)、Ripple v0.9.1和运行OS7.0的BlackBerry bold 9790上不起作用

注意:我还尝试使用
.on()
而不是
.bind()
,但没有成功。jQuery移动版(1.0.1和1.1.0)都失败了。

我用过这个,它确实可以工作

有没有可能是别的什么东西破坏了脚本或者mobileinit没有被解雇

Chrome会发射手机吗

我刚刚找到了一些我在jQueryMobile 1.0中使用的代码,我们刚刚升级到1.1.0,它可以正常工作

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

,所以我确信它是有效的。一定是出了什么事。对不起,我帮不了什么忙。你有更多的信息吗?或者尝试使用其他设备

[编辑]在同一个自我页面上,它说“因为mobileinit事件会立即触发,所以在加载jQuery Mobile之前,您需要绑定事件处理程序。按以下顺序链接到JavaScript文件:”



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

这里是另一个适用于我的简单示例(适用于android和ios)


$(document).bind(“mobileinit”,function()
{
if(navigator.userAgent.toLowerCase().indexOf(“android”)!=-1)
{
//你的逻辑在这里
$.mobile.defaultPageTransition='none';
$.mobile.defaultDialogTransition='none';
}
if(navigator.userAgent.toLowerCase().indexOf(“msie”)!=-1)
{
//你的逻辑在这里
$.mobile.allowCrossDomainPages=true;
$.support.cors=true;
}
});
  • 包括主jquery文件
  • 在jquery mobile之前绑定mobileinit
  • 包含jquery移动js文件

  • custom scripting.js
    文件将存储您的
    mobileinit
    事件处理程序,因此它受jQuery Mobile初始化时间(并触发
    mobileinit
    事件)的约束。我在文档中读过它后就知道了这一点,但它仍然让我感到困惑。谢谢你的这篇文章。节省了我几个小时@DaveR我知道这是一个总数,但自4月份以来,我没有与jQuery Mobile合作过多少,就在你发表评论的同一天,我正在用PhoneGap在jQM中编译一个应用程序。不管怎样,很高兴我能帮上忙!啊,嘎。谢谢你发布这个。
    <script src="jquery.js"></script>
    <script src="custom-scripting.js"></script> <!-- Note your script before jqm -->
    <script src="jquery-mobile.js"></script>
    
    <script type="text/javascript" src="files/resources/lib/jquery/jquery-1.8.2.js"> </script>
    <script type="text/javascript">
    $(document).bind("mobileinit", function()
                     {
                     if (navigator.userAgent.toLowerCase().indexOf("android") != -1)
                     {
                     // your logic here
                     $.mobile.defaultPageTransition = 'none';
                     $.mobile.defaultDialogTransition = 'none';
                     }
                     if (navigator.userAgent.toLowerCase().indexOf("msie") != -1)
                     {
                     // your logic here
                     $.mobile.allowCrossDomainPages = true;
                     $.support.cors = true;
                     }
                     });
    </script>
    <script type="text/javascript" src="files/resources/lib/jquerymobile/1.3.2/jquery.mobile-1.3.2.js"></script>