How does javascript's alert box display multiple lines in Java

  • 2020-03-30 02:59:34
  • OfStack

If you are directly in javascript code, you can display multiple lines with \n:
 
alert(" The first line n The second line "); 

But in Java code, \n doesn't work, \\n shows multiple lines!!
 
String strTemp=" History report: \n"+" You are right "+RdData.getCcnt()+" problem \n"+" Do you have "+RdData.getBcnt()+" No answer \n"+" You wrong "+RdData.getWcnt()+" The topic \n"; 
out.print("<script> alert('"+strTemp+"');window.location='index.jsp'</script>"); 

First, a String variable is declared (note that the newline is \\n!!). , and then put it in alert, and when you're done, the page jumps to the home page.

Here are the test results:
< img SRC = "border = 0 / / files.jb51.net/file_images/article/201405/20140518100352.jpeg? 20144181072 ">  
This is the special character code in javascript:
 
Code Outputs 
' single quote 
" double quote 
\ backslash 
n new line 
r carriage return 
t tab 
b backspace 
f form feed 

Related articles: