How to include JQuery in a javascript file without conflicts

Possible Duplicate:
Dynamically Including jQuery using JavaScript if it's not already present

I am making a site similar to google analytics in that I have my users paste a bit of javascript code on their site. My Question is how can I manage to include JQuery in my javascript snippet of code?

I already know how to include files using js: How do I include a JavaScript file in another JavaScript file?

But how do I make sure that there is no JQuery conflicts?

Gold star to anyone who suggests good practices in terms of generating embedded javascript code:)


The short answer is: You don't.

You should not impose a framework upon your users. Google does not do it with analytics, and you should not either. Use basic java script functionality only and write from scratch or copy what you need from other projects (as long as licenses permit).


总是测试一下,你所包含的内容还没有定义:

if(typeof jQuery === "undefined") {
   // include jQuery
}

I will suggest to use the jQuery no conflict function.

http://uzbekjon.hubpages.com/hub/How-to-use-jQuery_noConflict

Hope, it will help

链接地址: http://www.djcxy.com/p/62338.html

上一篇: jquery ui布局定制

下一篇: 如何在没有冲突的JavaScript文件中包含JQuery