When developing with jQuery, other JS libraries or plug-ins, such as Prototype, may be used. However, conflicts may occur when multiple libraries coexist, leading to various accidents. Next we will share with you several solutions to conflicts between jquery libraries and other libraries.
1. The jQuery library is imported before other libraries, and the jQuery (callback) method is used directly as follows:
<Html xmlns = "http://www.phpernote.com/php-function/849.html">
2. The jQuery library is imported after other libraries. The jQuery. noConflict () method is used to transfer the control of variable $ to other libraries. The following methods are available:
(1) method 1
<Script type = "text/javascript"> var $ j = jQuery. noConflict (); // customize a short shortcut $ j (function () {// use jQuery $ j ("p "). click (function () {alert ($ j (this ). text () ;}) ;}; $ ("p "). style. display = 'none'; // use prototype </script>
(2) method 2
<Script type = "text/javascript"> jQuery. noConflict (); // assign control of variable $ to prototype. jsjQuery (function ($) {// use jQuery $ ("p "). click (function () {// continue to use the $ method alert ($ (this ). text () ;}) ;}; $ ("p "). style. display = 'none'; // use prototype </script>
(3) method 3
<Script type = "text/javascript"> jQuery. noConflict (); // assign control of variable $ to prototype. js (function ($) {// defines an anonymous function and sets the parameter to $ (function () {// $ inside the anonymous function is jQuery $ ("p "). click (function () {// continue to use the $ method alert ($ (this ). text () ;};}) ;}( jQuery); // executes an anonymous function and passes the real parameter jQuery $ ("p "). style. display = 'none '; // use prototype /*********************************** * *********************************/jQuery (document ). ready (function () {// get the right out of jQuery when loading the page. noConflict () ;}); </script>Articles you may be interested in
- How to solve conflicts between concurrent read/write files in php
- Js restrictions: Only English letters and numbers can be entered. Chinese characters and other special characters cannot be entered.
- Windows cannot start the hardware device because its configuration information (in the Registry) is incomplete or damaged. (Code 19) Solution
- SetTimeout does not support other jquery selectors such as $ (this ).
- Rational use of MySQL database indexes to make the database run efficiently
- MySQL index Operation Command (create index, re-index, query index, delete index) Summary
- Js can only enter numbers and numbers with decimal points, compatible with IE and firefox
- Js shields mouse and keyboard events (including right-click, direction key, backspace key, F5 refresh key, etc.), compatible with IE and firefox