我正在尝试从 a 中获取值textarea
并将其放入 apre tag
中,它在 chrome 和 mozilla 上运行良好,但在 IE8 上,整个内容都保留在pre tag
jsbin链接:http: //jsbin.com/uwunug/4/edit
这就是全部:
<html><head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
</head>
<body>
<script type='text/javascript'>
$(function(){
$('#b1').click(function(){
x = $('textarea').val();
$('#tt').html(htmlEscape(x));
});
});
function htmlEscape(str) {
return String(str)
.replace(/&/g, '&')
.replace(/"/g, '"')
.replace(/'/g, ''')
.replace(/</g, '<')
.replace(/>/g, '>');
}
</script>
<textarea cols='50' rows='20'>
</textarea>
<button id='b1'>make code</button>
<pre class="prettyprint" id='tt'>
</pre>
</body>
</html>
我注意到(通过替换\n
为“输入”)\n
字符进入 pre 但它们不会在那里产生新行