怎样将html textarea的\n和
转换成br啊
请教各位大神
题主试试,,,,js,replace替换如下:
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<script type="text/javascript">
function replace_str() {
var p = document.getElementById("show"); //获取p标签
var str = p.innerHTML;//获取p标签的内容
var n = str.replace(/\\n/g, "<br>");//替换\n
var n = n.replace(/&#13/g, "<br>");//替换
p.innerHTML = n;
}
</script>
</head>
<body>
<input type="button" value="更改" onclick="replace_str()"/>
<p id="show">今
天天
气真好,\n真的好\n,真好啊\n</p>
</body>
</html>
replace方法详解见:http://www.w3school.com.cn/jsref/jsref_replace.asp
replace函数,js java都有这个函数
js?那不是直接replace就行了,只是js要用正则,要不只会替换一个,而且你的 少了分号吧。。实体对象要分号结束
<textarea id="ta">$(function() {
window.moveTo(0x190, 0x1e);
window.resizeTo(0x271, 0x2c1);
afe bcc ddd
</textarea>
<div id="dv"></div>
<script>
dv.innerHTML = ta.value.replace(/(\n| )/g, '<br>')
</script>