Thursday, April 12, 2012

How can I keep space, tab, CR and LF?

The string s include space, tab, CR and LF, alert(s) can render format correctly,
but $("#mydiv").text(s) lost CR and LF, I hope $("#mydiv").text(s) can render format correctly, how can I do ? Thanks!



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="Js/jquery-1.7.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$("#Button1").bind("click", function () {
alert(s);
$("#mydiv").text(s);
});
});
</script>
</head>
<body>
<p>
<input id="Button1" type="button" value="button" /></p>
<div id="mydiv">
</div>
</body>
</html>




No comments:

Post a Comment