2 Solutions for JQuery prototype conflict (with Demo sample download) _jquery

Source: Internet
Author: User

In this paper, we analyze 2 kinds of solutions of jquery prototype conflict. Share to everyone for your reference, specific as follows:

How jquery and prototype conflict, in the final analysis, is because they use $ two, at the same time, confused. This problem has been solved 5 times, each solution must check. Light pain, hehe.

Method One, add code to the kernel library file in jquery.

1, is generally jquery.js, or jquery.min.js, some with version number. It's OK to know which file it is.

}) (window);
Jquery.noconflict (); The last side, plus this line.

2. Load test jquery and prototype files

<script type= "Text/javascript" src= "Https://ajax.googleapis.com/ajax/libs/prototype/1.7.1.0/prototype.js" > </script>
<script src= "Jquery.min.js" ></script>

3, JS code writing

<script type= "Text/javascript" >
alert (' Prototype value: ' +$ (' test '). value);//prototype Writing
JQuery ( Document). Ready (function ($) {//note here, jquery and $
  alert (' jquery value: ' +$ (' #test '). Val ());//jquery writing
});
</script>

Recommend this method, this method is more permanent

The complete demo code is as follows:

 
 

Method Two, in the call jquery place, resolve the conflict

1. Load test jquery and prototype files

jquery and prototype, there is no order, who first after the same.
<script type= "Text/javascript" src= "Https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" ></script>
<script type= "Text/javascript" src= "https://ajax.googleapis.com/ajax/libs/prototype/ 1.7.1.0/prototype.js "></script>

2, JS code

<script type= "Text/javascript" >
jquery.noconflict ()//resolve conflict, this must be placed in the front of the JS code, or it will be an error.
alert (' Prototype value: ' +$ (' test '). value);
jquery (document). Ready (function ($) {
  alert (' jquery value: ' +$ (' #test '). Val ()
); </script>

This approach is better suited to jquery's core source files that are not on their own servers or with less jquery code. This sample demo points this view.

Full demo can click here to download the site.

I hope this article will help you with the jquery program design.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.