admin管理员组文章数量:1244245
I want to add a newline in alert message in javascript.
var al = $("#txt_noIncorrect").val().toString();
console.log(al); // al='Incorrect amount!\nFor decimals, use point instead of virgule.';
alert(al);
alert('Incorrect amount!\nFor decimals, use point instead of virgule.')
First alert:
Second alert:
Why first alert does not put the newline?
I want to add a newline in alert message in javascript.
var al = $("#txt_noIncorrect").val().toString();
console.log(al); // al='Incorrect amount!\nFor decimals, use point instead of virgule.';
alert(al);
alert('Incorrect amount!\nFor decimals, use point instead of virgule.')
First alert:
Second alert:
Why first alert does not put the newline?
Share Improve this question asked May 21, 2014 at 8:17 POIRPOIR 3,1909 gold badges34 silver badges48 bronze badges 4- 2 sidenote: "point" and "virgule" are in French. The English terms for these punctuation marks are "dot" (or "full stop") and "ma". – The Paramagnetic Croissant Commented May 21, 2014 at 8:20
-
1
Could you try
.text()
instead of.val()
. And drop the.toString()
– Gerben Jacobs Commented May 21, 2014 at 8:21 - works fine in FF. Can make fiddle with example? – deadulya Commented May 21, 2014 at 8:25
-
1
If your
console.log()
shows\n
rather than a new line, then it means that the character \ is escaped. – Mivaweb Commented May 21, 2014 at 8:26
3 Answers
Reset to default 8You could do this alert("Hello \r\nWorld");
You can do this by replacing the \n with a new line character in Javascript using .replace()
alert($("input[type='text']").val().replace(/\\n/g,"\n"));
FIDDLE DEMO
UPDATE
Here is a fiddle example with textarea instead of input text. JSFIDDLE DEMO
try this alert("Hello \n World");
本文标签: jqueryNewline in alert javascriptStack Overflow
版权声明:本文标题:jquery - Newline in alert javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1740182871a2237661.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论