" jQuery的(...)"而不是“$(...)” [英] "jQuery(...)" instead of "$(...)"

查看:73
本文介绍了" jQuery的(...)"而不是“$(...)”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编写 jQuery(...)而不是 $(...)

我听说如果他们使用 $ 同样,这是一个现实世界的关注?假设我真的不知道我将来会使用哪些其他库,那么我应该避免在我的脚本中编写 $(...)吗?是否有其他知名图书馆依赖 $

I heard that it might be useful for avoiding future conflicts with other libraries if they use the $ as well, but is that a real-world concern? Let say I really have no idea what other libraries I'm gonna use in the future, so should I avoid writing $("...") in my scripts? Is there any other well known libraries relying on $ as well?

此外,我很想知道是否有是这个主题附带的任何其他问题。

Also I'd love to know if there is any other issues attached to this subject.

推荐答案

使用$ for jQuery是完全安全的,它是jQuery的成语,at至少在你自己控制的页面上。

It's perfectly safe to use the $ for jQuery, it's the jQuery idiom, at least on your own pages which you control.

如果你确实选择在小部件中使用jQuery,你可以用一种方式来构建它以防止它发生冲突。

If you do choose to use jQuery in widgets you can structure it in a way that prevents it from conflicts.

一般来说,jQuery绑定到$和jQuery,所以单独使用jQuery并不能保证你的安全..

In general jQuery binds to both $ and jQuery so using jQuery alone does not guarantee you safey..

如果你担心的话与jQuery冲突确实暴露了$ .noConflit();
http://api.jquery.com/jQuery.noConflict/

If you are concerned with conflict jQuery does expose the $.noConflit(); http://api.jquery.com/jQuery.noConflict/

放弃对$的控制,你可以将jQuery存储在你选择的变量中(或者使用jQuery)。

Which relinquishes the control of $ and you can store jQuery in a variable of your choice (or use jQuery).

以下是基于维基百科页面使用$符号的库,以及 stackoverflow答案

Here are the libraries that use the $ sign based on the Wikipedia page and this stackoverflow answer:


扫描此页面时,唯一想到的是:

Scanning this page, the only ones that come to mind are:


  1. jQuery - 提供jQuery.noConflict()来释放$

  2. 原型

  3. MooTools


然而,jQuery以约90%的市场份额杀死它。

However jQuery is killing it with about 90% market share..


  1. http://www.theregister.co.uk/2012/08/14/jquery_used_by_half_of_all_websites/

  2. https://stackoverflow.com/questions/176324/why-does-everyone-like-jquery-more-than-prototype-script-aculo-us-or-mootools-or

  1. http://www.theregister.co.uk/2012/08/14/jquery_used_by_half_of_all_websites/
  2. https://stackoverflow.com/questions/176324/why-does-everyone-like-jquery-more-than-prototype-script-aculo-us-or-mootools-or

这篇关于" jQuery的(...)"而不是“$(...)”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆