开发者

Odd behavior in javascript

开发者 https://www.devze.com 2023-03-01 12:34 出处:网络
When I write this: var loc = \"a,a\\n\"; alert(loc); 开发者_Go百科 It shows \"a...\" in alert. Then after I add some values in loc as

When I write this:

var loc = "a,a\n";
alert(loc);
开发者_Go百科

It shows "a..." in alert. Then after I add some values in loc as

loc = loc + "abc," + valueFromFunc;
alert(loc);

It shows "ab...a,a\nabc,value" in alert. Why I get a.. and ab.. in loc? I want loc to be "a,a\nabc,value"


I'm using Google Chrome. When I tried it in IE it works great but in chrome I got above output.

Screen shot of my google chrome:

Odd behavior in javascript


I think that thing with the dots is from the browser. In Win Chrome it appears, but under Linux - no.

If you want to dispalay \n use a double slash, to show the second one.

var loc = "a,a\\n";
var valueFromFunc = "gdfgdfg fdgdfg";
loc = loc + "abc," + valueFromFunc;
alert(loc);
0

精彩评论

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