javascript 在javascript中处理未终止的字符串常量
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17107744/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
handle unterminated string constant in javascript
提问by commit
When my sql server SP returning string with new line character and in my jsp I pass it to script function and display it in alert box it throws :
当我的 sql server SP 返回带有换行符的字符串并在我的 jsp 中时,我将其传递给脚本函数并将其显示在警告框中,它会抛出:
function sample(notes){
alert(notes);
}
Error:
script1015: unterminated string constant
I can handle it in SP like
我可以像 SP 一样处理它
REPLACE(BDT.Notes , CHAR(13) + CHAR(10), ''<br/>'' ) as Notes
But is there any way to handle it in script?
但是有没有办法在脚本中处理它?
回答by M Sach
try below
试试下面
someText = someText.replace(/(\r\n|\n|\r)/gm,"");
see link http://www.textfixer.com/tutorials/javascript-line-breaks.php
见链接http://www.textfixer.com/tutorials/javascript-line-breaks.php