admin管理员组文章数量:1389897
I want to display special chars as an alert box using javascript and jsp...
String encodeString = "ss\ncc";
String test = "DisplayNext('"+encodeString+"')";
String NextLink = "<br><a href='#' onclick="+test+"> Next</a>";
That is
function DisplayNext(Next){
alert(Next);
}
Though I've used special chars I am not able to display them in an alert box. How can I sort this out?
I want to display special chars as an alert box using javascript and jsp...
String encodeString = "ss\ncc";
String test = "DisplayNext('"+encodeString+"')";
String NextLink = "<br><a href='#' onclick="+test+"> Next</a>";
That is
function DisplayNext(Next){
alert(Next);
}
Though I've used special chars I am not able to display them in an alert box. How can I sort this out?
Share Improve this question edited May 17, 2017 at 11:02 cweiske 31.2k15 gold badges147 silver badges205 bronze badges asked May 12, 2011 at 8:46 Manish BasdeoManish Basdeo 6,27923 gold badges72 silver badges103 bronze badges 1- 8 You've posted 67 previous questions. With respect, you should be able to format code by now. See the handy How to Format box to the right of the question area, and the page linked from the [?] just above the question area. – T.J. Crowder Commented May 12, 2011 at 8:48
2 Answers
Reset to default 6Your code produce something like this:
<br><a href='#' onclick="DisplayNext('ss
cc');"> Next</a>
And what you need is:
<br><a href='#' onclick="DisplayNext('ss\ncc');"> Next</a>
If you want a line break in javascript it must look as \\n
in java. So use:
String encodeString = "ss\\ncc";
String test = "DisplayNext('"+encodeString+"')";
String NextLink = "<br><a href='#' onclick="+test+"> Next</a>";
Also consider using a special function to escape your String objects as javascript values. Google will easily help you find it ;)
If your String is URLEncoded in java you need to unescape it in javascript.
Java:
String s = "ë";
System.out.println(URLEncoder.encode(s, "ISO-8859-1"));
this will print out %EB
Javascript:
alert(unescape('%EB'));
this will print out the character ë in alert message
本文标签: javaHow can I display special chars in an alert box using javascriptStack Overflow
版权声明:本文标题:java - How can I display special chars in an alert box using javascript? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744584910a2614141.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论