如何避免两次调用jquery [英] How can I avoid calling jquery twice

查看:94
本文介绍了如何避免两次调用jquery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Jquery表单插件提交我的表单.我的html文件的head标签看起来像下面的

I am using Jquery Form Plugin to submit my form. The head tag of my html file looks like following

<script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>
 then 10 other javascript files

AND Then   
<script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="js/jquery.form.js">
<script type="text/javascript"> 
       $(document).ready(function() { 
      var options = { 
                       success:       showResponse
                         };
                         $('#myForm').ajaxForm(options); 
        }); 
  </script>         

要查看我的代码的实际图片,请检查此 http://jsfiddle.net/Xfrms/1/

To see the actual picture of my code please check this http://jsfiddle.net/Xfrms/1/

问题是,即使我在代码的最顶部调用了jquery library,如果我没有在jquery.form.js插件之前调用jquery库,那么它(jquery.form.js)也不会工作.在query.form.js插件在最顶部调用jquery库之后,我试图调用其他10个javascript文件,但是在这种情况下,调用javascript文件的功能不起作用.

The problem is even though I call jquery library on the very top of my code, if I don't call the jquery library right before the jquery.form.js plugin then it (jquery.form.js) doesn't work. I have tried to call those 10 other javascript files after the query.form.js plugin calling the jquery library on the very top but in this case the functionality for which the javascript files are being called doesn't work.

看到此帖子后,我认为两次调用jquery可能会引起问题.

After seeing this post, I think calling jquery twice can cause problems.

能否请您告诉我我的代码中可能出什么问题以及如何避免必须在jquery表单插件之前加载jquery但仍能使它正常工作?

Could you please tell me what could possibly going wrong in my code and how to avoid having to load jquery right before the the jquery form plugin but still get it working?

谢谢

推荐答案

我可以想象您的问题是,其他一些库正在使用$关键字标记实例化每个调用.如果我是正确的,请尝试以下方法,一切准备就绪.

As I can imagine your problem is that some of the other libraries is using the $ keyword markup to instantiate each calls. If I am correct the just try the following and you will be all set to go..

var $jq = jQuery.noConflict();

然后对所有jquery调用尝试使用新标记.$ jq.

Then for all of your jquery calls try use your new markup.. the $jq.

有关更多详细信息,请查看此页面: http://docs.jquery.com/Using_jQuery_with_Other_Libraries

For more detailed info check out this page: http://docs.jquery.com/Using_jQuery_with_Other_Libraries

在页面开头使用js脚本参考,以确保在开始时正确加载了所有代码.此外,加载所有脚本可能会填充一些错误.要检查是否存在任何错误,请使用一些调试插件(如Firebug).

Use the js script reference at the beginning of your page to ensure that all code is loaded properly at start. Moreover it is likely that some error could be populated from loading all scripts.. To check if any errors exist, use some debugging plug in like Firebug.

这篇关于如何避免两次调用jquery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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