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.