两次加载jQuery会导致错误? [英] loading jquery twice causes an error?

查看:98
本文介绍了两次加载jQuery会导致错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个页面正在加载jquery和其他js:

I have a page where jquery + other js's is being loaded:

<script src="/eiv/javascripts/jquery-1.3.2.min.js" type="text/javascript"></script>
<script src="/eiv/javascripts/jquery.jeditable.js" type="text/javascript"></script>
<script src="/eiv/javascripts/jquery-ui-1.7.1.custom.min.js" type="text/javascript"></script>
<script src="/eiv/javascripts/corner.js" type="text/javascript"></script>
<script src="/eiv/javascripts/jquery.form.js" type="text/javascript"></script>
<script src="/eiv/javascripts/validationdate.js" type="text/javascript"></script>

我正在加载标签,如下所示:

I am loading tabs as follows:

<%if (tabnum == 1) {%>
        <script type="text/javascript">

            $(document).ready(function(){
                $("#tabs").tabs();
                $("#tabs ul li a").corner('7px top');

               var $tabs = $('#tabs').tabs();
                $tabs.tabs('select', 0);
                dateValidation();
                changeOption();
                deleteConfirmation();
        });
        </script>
<%} else if (tabnum==2) {%>
        <script type="text/javascript">

            $(document).ready(function(){
                $("#tabs").tabs();
                $("#tabs ul li a").corner('7px top');

               var $tabs = $('#tabs').tabs();
                $tabs.tabs('select', 1);

                   changeOption();
                   deleteConfirmation();
        });
        </script>
<%}%>

validationdate.js是我的内置js,用于检查日期和其他内容.它的第一行是这样的:

the validationdate.js is a mine built js that checks dates and other stuff. it has this as the first line:

document.write('<script type="text/javascript" src=""jquery-1.3.2.min.js""></script>');

问题: 是否在生产中..this页面错误并给出了JS错误.这将导致该选项卡不可单击.该错误间歇性地发生,我似乎无法在我的机器上重现它.两台机器都使用IE.在Firefox中也会发生错误,尽管在Firefox中并没有显示JS错误.而且我什至还有萤火虫,它也没有显示任何JS错误.

Problem: Is that in production at time ..this page errors out and give a JS error. This causes the tab's to be not clickable. This error happens intermittently and I can not seem to reproduce it on my machine. Both machines are using IE. Error also happens in Firefox, though little JS error thing does not show up in firefox. and I even have firebug which does not show any JS error either.

我怀疑会出现错误,因为validationdate.js也正在加载jquery-1.3.2.min.js.这会是一个错误吗?

I suspect that error is coming up because validationdate.js is also loading jquery-1.3.2.min.js. Can this be an error?

顺便说一句,我得到的JS错误是'捕获了异常但未抛出..第23行',并且紧随其后的是第23行

By the way, the JS error I get is 'Exception caught but not thrown ..line 23' and line 23 is following

<script src="/eiv/javascripts/jquery-1.3.2.min.js" type="text/javascript"></script>

我真的不在这里了,我愿意尝试一些东西.以及在我的机器上重现的方式,以便我可以修复它!

I am really out of options here and am willing to try stuff out. and also ways to reproduce on my machine so i can fix it!!

推荐答案

首先回答您的问题,,其中包括jQuery两次,都可能导致各种问题.

First to to answer your question, yes, including jQuery twice can cause all sorts of issues.

要修复此问题,请执行以下行:

To fix it, this line:

document.write('<script type="text/javascript" src=""jquery-1.3.2.min.js""></script>');

应该包装起来以检查jQuery是否已经存在,而不是盲目地再次包含它,像这样:

Should be wrapped to check if jQuery already exists instead of blindly including it again, like this:

if (typeof jQuery == 'undefined') {  
  document.write('<script type="text/javascript" src=""jquery-1.3.2.min.js""></script>');
}

然后,仅当页面上没有jQuery时,它才会包括它.有一个警告,如果您使用的版本不同的(可能是较新的)版本的jQuery而不是为其构建验证代码的版本,则有可能会出现一些中断.

Then, it will only include it if jQuery isn't already on the page. There is one caveat, if you're using a different (probably newer) version of jQuery than the validation code was built for, there's a chance there are some breaks.

这篇关于两次加载jQuery会导致错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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