开发者

Have problem with multi-line string in javascript

开发者 https://www.devze.com 2023-04-08 22:59 出处:网络
This works: alert(\'foo\\ 开发者_开发百科bar\' ) But this is causing syntax error: t=\'test\'; alert(\'<tr><td><b>\' + t + \'</b></td>\\

This works:

alert('foo\
   开发者_开发百科      bar'
)

But this is causing syntax error:

t='test';
alert('<tr><td><b>' + t + '</b></td>\ 
                    <td></td><td>')

error is:

SyntaxError: unterminated string literal

They two should be the same thing, why the first one works, while the second fails?


You have a trailing space after your backslash in the second example.

0

精彩评论

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

关注公众号