在javascript中处理未终止的字符串常量

com*_*mit 0 javascript java sql-server jsp

当我的sql server SP返回带有新行字符的字符串并在我的jsp中我将它传递给脚本函数并在警告框中显示它抛出:

function sample(notes){
    alert(notes);
}

Error:
script1015: unterminated string constant 
Run Code Online (Sandbox Code Playgroud)

我可以在SP中处理它

REPLACE(BDT.Notes , CHAR(13) + CHAR(10), ''<br/>'' ) as Notes
Run Code Online (Sandbox Code Playgroud)

但有没有办法在脚本中处理它?

M S*_*ach 5

试试下面

 someText = someText.replace(/(\r\n|\n|\r)/gm,"");
Run Code Online (Sandbox Code Playgroud)

请参阅链接http://www.textfixer.com/tutorials/javascript-line-breaks.php