loading jquery twice causes an error?

前端 未结 3 2037
慢半拍i
慢半拍i 2020-12-01 14:42

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

         


        
相关标签:
3条回答
  • 2020-12-01 15:21

    Using an iframe will cause JQuery to load twice if you
    1) load JQuery for each page (i.e. in Ruby on Rails via application.html.erb) and
    2) the iframe is also a page from your application rather than an iframe of an external site.

    0 讨论(0)
  • 2020-12-01 15:25

    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>');
    

    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>');
    }
    

    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.

    0 讨论(0)
  • 2020-12-01 15:31

    i spent hours figuring out why using jQuery.noConflict() doesn't work as is...

    Just use var j$ = jQuery.noConflict(); and after that use j$ in place of $ every time you use Jquery on that page.

    0 讨论(0)
提交回复
热议问题