“document.ready()”功能未在Chrome Mobile上启动(android) [英] The "document.ready()" function not firing on Chrome Mobile (android)

查看:83
本文介绍了“document.ready()”功能未在Chrome Mobile上启动(android)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在标签之前调用了jQuery-2.1.4.min.js,但是当我写下这样的内容时:

I have jQuery-2.1.4.min.js called before the tag, but when I write something like:

<script type="text/javascript" src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
<script type="text/javascript">
    jQuery(document).ready(function() {
        alert('hi, world.');
    });
</script>

在我的电脑上它当然被解雇了,但是在十个不同的Android设备上却没有。这是纯粹的HTML / CSS / jQuery呈现网站(没有手机屏幕或其他任何东西)。

On my PC it is fired of course, but on ten different Android devices it just does not. This is purely HTML/CSS/jQuery rendered site (no phonegap, or anything).

我的目标是在点击按钮后按钮执行ajax请求,但是我甚至无法测试,因为.ready()函数在移动Chrome上根本没有触发。

My goal was to have a button do ajax request after it's being tapped, but I can't even test that, because the .ready() function is not firing at all on mobile chrome.

jQuery是从官方CDN提供的,任何帮助非常感谢。

The jQuery is being served from the official CDN, any help would be very much appreciated.

尝试了两种方式:

$(function() {
   alert('hi, world.');
});

jQuery(document).ready(function() {
    alert('hi, world.');
});

同样的事情。

按照建议我还试过:

window.onload = function()
{
    if (window.jQuery)
    {
        alert('jQuery is loaded');
    }
    else
    {
        alert('jQuery is not loaded');
    }
}

它警告'jQuery已加载'。

And it alerts 'jQuery is loaded'.

根据jQuery文档,它说:$(文档).ready()中包含的代码只有在页面文档对象模型(DOM)准备好使用JavaScript代码时才会运行执行 - 这意味着DOM还没有准备好执行JavaScript代码?但是,当我尝试:

As per jQuery docs it says: "Code included inside $( document ).ready() will only run once the page Document Object Model (DOM) is ready for JavaScript code to execute" - which would mean that DOM is not ready for JavaScript code to execute? But when I try like:

<script type="text/javascript">
    alert('hi world');
</script>

它在移动Chrome上执行。

It executes on mobile Chrome.

推荐答案

好的,经过广泛的调查后,如果你有两次document.ready()函数,似乎JS打破了移动chrome,我的core.js文件中有一个,而且页。

Okay, after extensive investigation it seems that JS breaks on mobile chrome if you have document.ready() function twice, I had one in my core.js file and one in-line on the page.

它在PC(所有浏览器)上运行正常,但在移动设备上它可以工作到第二次ready()调用并在此之后中断所有JS。

It works okay on PC (all browsers), but on mobile it works up to the point of second ready() call and breaks all JS after that.

希望将来可以为其他人节省一些时间。

Hopefully this saves some time to others in the future.

这篇关于“document.ready()”功能未在Chrome Mobile上启动(android)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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