开发者

What's causing parse error in JavaScript when source code is cut and pasted?

I cut and pasted this SO code snippet from my browser into my editor (TextWrangler). When I loaded the page it gave me a Syntax/Parse error (Safari).

After staring at it for about 10 minutes, I retyped the exact same code manually, and it executed as expected without any parse errors.

Curious if anyone else gets the same result, and I'm assuming there must be some hidden characters that are messing up the JavaScript syntax..? Does anyone know which characters these would likely be (returns? tabs?) and how do you deal with this - is it just an editor problem? Usually I have no problems with cutting and pasting code from my browser window into my code editor..

Months later and this is still an open issue.

Similar thing happened again, cut and pasted some CSS into Vim:

.quiz-button-go:hover{
    color:#ddffff;
    background:#28e07e;
}

the color attribute will not work (it is ignored in the browser), but the background DOES work. However if I delete the spaces before color and the newline, then the color attribute works!

I found that in Vim you can use :set list to display all hidden characters. This is what I get:

44 .quiz开发者_如何学C-button-go:hover{$
45    $
46 ^Icolor:#ddffff;$
47 ^Ibackground:#28e07e;$                                                                                              
48 }$

Nothing out of the ordinary, right?

furthermore, if I try cat -vt filename, I get this:

.quiz-button-go:hover{
^Icolor:#ddffff;
^Ibackground:#28e07e;
}

Again, if I simply delete the empty space before "color", the CSS works perfectly.

Any other ideas on how to view hidden chars would be appreciated...


Not completely sure, but probably there were hidden unrecognized symbols in the code you copied and pasted. And it caused the error.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜