JQuery multi-database coexistence Optimal Solution

Source: Internet
Author: User
Tags jquery library
I have been using jQuery for a while and read two books about jQuery. the Chinese name of "jQuery in Action", "jQuery practice", is indeed well written. It seems that I have no sleep at night. There is also a Chinese book "Learning jQuery" titled "Basic jQuery tutorials". To be honest, this book is not very well written, and it was quite good before I read "jQuery in Action, after reading jQuery in Action, I felt that the things I was talking about were a little simple and not deep enough. He talked about a lot of things that I'm not interested in. In fact, the next plug-in on the internet is actually done.
Okay. Let's take a look at how to solve the problem of jQuery coexistence.
The official method is as follows:
JQuery. noConflict (). When this method is called, a value is returned. The returned value can be understood as: Get an alias for the $ function of jQuery.
This method is explained as follows:
Run this function to assign control of variable $ to the first database to implement it.
This helps ensure that jQuery does not conflict with $ objects in other libraries.
After running this function, you can only use jQuery variables to access jQuery objects. For example, to use $ ("div p"), you must replace it with jQuery ("div p ").
Note: This function must be used after you import the jQuery file and before importing another library that causes the conflict. Of course, it should also be before other conflicting libraries are used, unless jQuery is the last imported.
OK. As a result, $ is useless. This is not very depressing. I don't want to get used to $'s throwing other function names. What should we do? The method is still available, as shown in the following code:
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN "" Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<Html http://www.w3.org/1999/xhtml "target = _ blank> http://www.w3.org/1999/xhtml ">
<Head>
<Title> </title>
<Script type = "text/javascript" src = "jquery-1.3.2.min.js"> </script> <! -- Import jQuery library, of course, the website should use pressure files, development in VS08 using jquery-1.3.2-vsdoc.js, There Will Be Smart Tips -->
<Script type = "text/javascript">
$ = Document. getElementById; // defines a $ function, which conflicts with the $ function of jQuery.
(Function ($) {// use the anonymous method (Closure {the specific name is not clear, let's call it first}) to receive a parameter $
$ (Function (){
$ ("# Show" ).css ({border: "1px dotted #336699", width: "200px", height: "150px", color: "red" Shopping Mall .html ("The weather is good today. It's very elegant! ");
});
}) (JQuery); // pass parameters to the previous anonymous function. jQuery is stored in the previous $,
</Script>
</Head>
<Body>
<Div id = "show"> </div>
</Body>
</Html>
OK. With this, we don't have to worry about using $ for multiple databases.

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.