开发者

Confusing Javascript quotes

In t开发者_如何学运维he jQuery docs mostly every string is "declared" using single quotes. Including the documentation for jQuery UI.

So why doesn't this

$(".datepicker").datepicker({ dateFormat: 'dd.mm.yy' });

work, but this

$(".datepicker").datepicker({ dateFormat: "dd.mm.yy" });

does? When using single quotes, the datepicker ignores my dateFormat setting.

(Ignore my silly habit of using double-quotes in the jQuery selector, but single quotes everywhere else :P )


They're identical. Javascript can use single or double qotes for string literals.

Therefore, you must have an error elsewhere that is causing you a problem. Try to distill a test page down to the bare minimum to try to ascertain where this error could be.


Mmm.. Maybe here is the answer. But, anyway, I still can't understand why you have an error here.


What you are saying is impossible.
Javascript has no way of knowing if single or double quotes are being used in an object literal ({string: "string"}); and even if it did, datepicker and jQuery(UI) doesn't care.

Now, if you are receiving the object-literal as a JSON object via XMLHttpRequest (or just parsing the an object-literal as JSON) single quotes will fail, though so will unquoted names in the name/value pair like you have in your example.

The only other thing I can think of that would cause this problem is if you are using backticks (`) or curly quotes instead of single quotes (‘’).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜