Javascript jQuery 中的单引号或双引号
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7027986/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Single or Double quotes in jQuery
提问by Ricardo Zea
Possible Duplicate:
When to Use Double or Single Quotes in 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.
在此先感谢您的澄清。
采纳答案by Frink
JQuery Core Style Guidelinessays:
"Strings should always use double-quotes instead of single-quotes."
“字符串应该始终使用双引号而不是单引号。”
回答by js-coder
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 问题。您正在向$()
函数传递一个字符串,并且字符串必须用'
或包围"
。
回答by Michael Stum
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 在这里改变了什么有什么具体原因吗?