admin管理员组文章数量:1321241
for example here in documentation / it says
$('input[name*="man"]')
I would write instead
$("input[name*='man']")
is there any reason to use single or double quotation marks on inside or outside ?? is it just a matter of taste?
for example here in documentation http://api.jquery./attribute-contains-selector/ it says
$('input[name*="man"]')
I would write instead
$("input[name*='man']")
is there any reason to use single or double quotation marks on inside or outside ?? is it just a matter of taste?
Share Improve this question edited Jan 15, 2012 at 10:31 Felix Kling 817k181 gold badges1.1k silver badges1.2k bronze badges asked Jan 15, 2012 at 9:10 IAdapterIAdapter 64.9k73 gold badges186 silver badges243 bronze badges 4- 2 Duplicate of stackoverflow./questions/242813/… – Shai Mishali Commented Jan 15, 2012 at 9:12
- 1 @ShaiMishali: Not a duplicate, as this also involves the syntax for jQuery selectors. – Guffa Commented Jan 15, 2012 at 9:39
- @Guffa I don't really agree. jQuery is just a Javascript library and the "quotes" thing is the same for both. – Shai Mishali Commented Jan 15, 2012 at 14:52
- 2 @ShaiMishali: Yes, jQuery is not a separate language, but the selectors used by jQuery is. It's not Javascript that is used in the selectors, but a syntax based on CSS selectors. The fact that Javascript syntax and selector syntax uses the same quotation marks has nothing to do with the fact that jQuery is a Javascript library. – Guffa Commented Jan 15, 2012 at 14:59
2 Answers
Reset to default 5It's just a matter of taste, and sometimes convenience.
You are using quotation marks both in Javascript and in a jQuery selector, and in both cases you can use either apostrophes (') or quotation marks (") to delimit strings.
In some cases it's more convenient to use one type over the other, for exampe when you have Javascript code in an HTML attribute, as apostropes doesn't need to be escaped:
<div onclick="alert('Hello world!');">
pared to:
<div onclick='alert("Hello world!")'>
Yes, it's a matter of taste. I generally use double quotes when the string literal contains single quotes, and vice-versa, to avoid having to escape them.
本文标签: javascriptWhich quotation marks to use and whenStack Overflow
版权声明:本文标题:javascript - Which quotation marks to use and when? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742097591a2420644.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论