Possible Duplicate:
When to Use Double or Single Quotes in JavaScript可能的副本:在JavaScript中使用双引号或单引号。
This is specifically for jQuery not JavaScript in general since I'm not a JavaScript programmer and I'm starting to learn jQuery.
这是专门针对jQuery而不是JavaScript的,因为我不是JavaScript程序员,我开始学习jQuery。
With the release of jQuery 1.6 was there a specific change on using single or double quotes?
随着jQuery 1.6的发布,使用单引号还是双引号有什么特别的变化吗?
For example, would the following function work in jQuery 1.6?:
例如,以下函数是否可以在jQuery 1.6中工作?
$('.selector').show();
Or do I have to use double quotes?:
或者我必须使用双引号?
$(".selector").show();
Thanks in advance for any clarification.
感谢您的澄清。
3 个解决方案
#1
36
JQuery Core Style Guidelines says:
JQuery核心风格指南说:
"Strings should always use double-quotes instead of single-quotes."
字符串应该使用双引号而不是单引号。
#2
14
You are allowed to use both. In JavaScript there is no difference between both (while e.g. in PHP there is a difference).
你可以两者都用。在JavaScript中,两者之间没有区别(例如在PHP中有区别)。
By the way, this is a JavaScript question. You are passing a string to the $()
function, and strings have to be surrounded by '
or "
.
顺便说一下,这是一个JavaScript问题。将字符串传递给$()函数,字符串必须被'或'包围。
#3
8
jQuery is JavaScript and as such emits the same behavior: Both behave the same, because both represent a string.
jQuery是JavaScript,它会发出相同的行为:它们的行为都相同,因为它们都表示一个字符串。
Is there any specific reason you think that jQuery 1.6 changed something here?
您认为jQuery 1.6在这里有什么特别的原因吗?
#1
36
JQuery Core Style Guidelines says:
JQuery核心风格指南说:
"Strings should always use double-quotes instead of single-quotes."
字符串应该使用双引号而不是单引号。
#2
14
You are allowed to use both. In JavaScript there is no difference between both (while e.g. in PHP there is a difference).
你可以两者都用。在JavaScript中,两者之间没有区别(例如在PHP中有区别)。
By the way, this is a JavaScript question. You are passing a string to the $()
function, and strings have to be surrounded by '
or "
.
顺便说一下,这是一个JavaScript问题。将字符串传递给$()函数,字符串必须被'或'包围。
#3
8
jQuery is JavaScript and as such emits the same behavior: Both behave the same, because both represent a string.
jQuery是JavaScript,它会发出相同的行为:它们的行为都相同,因为它们都表示一个字符串。
Is there any specific reason you think that jQuery 1.6 changed something here?
您认为jQuery 1.6在这里有什么特别的原因吗?