$(document).ready在IE中不起作用 [英] $(document).ready doesn't work in IE

查看:296
本文介绍了$(document).ready在IE中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的页面中有两个链接,注册和登录。

In my page there is two links, register and login.

现在重要的是注册。当我单击它时,它使用jquery加载函数加载.tpl文件。在这个tpl文件中,我包含一个带有< script> ofcourse的新js文件,它在safari,ff,opera和chrome中完美运行,但当然,为什么要这样做在IE工作?

The important one now is register. When I click it, it loads a .tpl file using jquery load function. In this tpl file I include a new js file with <script> ofcourse, and it works perfectly in safari, ff, opera and chrome, but of course, Why should it be working in IE?

所以我的问题是,我该怎么做才能让它在IE中运行?我想如果我将js放在.tpl文件中可以解决我的问题,但是如果有更好的解决方案,我想听听它。没有这没有帮助,所以我猜没有解决方案:D

现在我尝试了一个简单的警报,它工作得很好。

Now I tried it with a simple alert, it worked perfectly.

我的问题已经改变了。如果JS文件中有一个 $(document).ready ,那么IE忽略整个脚本,但如果不存在则完美无缺。问题是我需要准备好该文件。 :D

My problem has changed. If there is a $(document).ready in the JS file the IE "ignores" the whole script, but if there isn't it works perfectly. The thing is that i need that document ready. : D

谢谢。

推荐答案

如果脚本被忽略 如果有$(文档)准备就绪,那么脚本的那个块可能会出错,并且IE被设置为在出错时停止运行脚本。

If the script is "ignored" if there's a $(document)ready then there may be an error in that block of the script and your IE is set to stop running scripts on error.

尝试简化您的问题以尝试指出它。例如,将以下代码复制到一个全新的html文件中并试用(注意:您需要将src路径更改为jquery.js文件。)

Try to simplify your issue a bit to try to pin point it. For example, copy the following code into a brand new html file and try it out (NOTE: you'll need to change the src path to the jquery.js file.)

<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function() {
    alert('test');
}
</script>
</head>
<body>
</body>
</html>

以上是否适合您使用IE或是否也会被忽略(再次更新jquery.js文件的路径后)?

Does the above work in IE for you or does it get ignored as well (again, after you update the path to the jquery.js file)?

如果这样可行,但它不适用于您的场景,请检查您的页面在IE中的来源,了解所有内容的加载方式。唯一一次我看到$(document).ready()抛出错误的时候是jquery.js文件是没有在它之前加载或者与$()函数发生冲突......在这种情况下你需要noConflict()函数。

If this works but it doesn't in your scenario, check your page's source in IE for how everything is loaded. The only time I've seen $(document).ready() throw an error is when the jquery.js file is not loaded prior to it or there's a conflict with the $() function...in which case you'll need the noConflict() function.

这篇关于$(document).ready在IE中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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