textarea换行问题,求大神 textarea标签换行问题,比如说我在textarea编辑框中输入多行(如果不加<br />),然后获取值显示在div中,得到的只有一行,现在是我想在textarea中输入什么样的格式,然后在div中显示什么样的格式 怎么解决? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <!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=gb2312" /> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.js" type="text/javascript"></script><style type="text/css"></style><script type="text/javascript"> $(function(){ $("#textarea1").keyup(function(){ $("#div2").html($("#textarea1").val().replaceAll("\n","<br/>")); }); }); String.prototype.replaceAll = function(s1, s2) { var r = new RegExp(s1.replace(/([\(\)\[\]\{\}\^\$\+\-\*\?\.\"\'\|\/\\])/g,"\\$1"),"ig"); return this.replace(r,s2); }</script></head> <body><textarea id="textarea1" style="width:200px;height:100px;"></textarea><div id="div2" style="width:200px;height:100px;border:dashed 1px red;overflow-y:auto;"></div></body> </html> 本帖最后由 net_lover 于 2012-11-24 14:34:23 编辑 不好意思,.replaceAll("\n","<br/>"))<br/>被csdn弄成了一个空格 楼主:你要注意啊,replace是不行的!如果我上的代码,你用replace, 只能替换一个回车。所以你一定要用我上面的那个自定义的 replaceAll !!!!!!!!! 如何在DIV中插入图片? 关于JS控制右下角弹窗的问题 像系统的学JS,大家推荐一本书 JSP 问题 请问如何用JS实现 限制鼠标移动区域的功能 如何实现点击框架中的按钮,关闭浏览器窗口? function()括号内的参数类型是非只能为int型? 怎么会取不到值 怎么样自定义鼠标右键菜单 这个该如何写呀!! 动态树形菜单刷新问题 20行代码,找错,谢谢了
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.js" type="text/javascript"></script>
<style type="text/css">
</style>
<script type="text/javascript">
$(function(){
$("#textarea1").keyup(function(){
$("#div2").html($("#textarea1").val().replaceAll("\n","<br/>"));
});
});
String.prototype.replaceAll = function(s1, s2) {
var r = new RegExp(s1.replace(/([\(\)\[\]\{\}\^\$\+\-\*\?\.\"\'\|\/\\])/g,"\\$1"),"ig");
return this.replace(r,s2);
}
</script>
</head>
<body>
<textarea id="textarea1" style="width:200px;height:100px;"></textarea>
<div id="div2" style="width:200px;height:100px;border:dashed 1px red;overflow-y:auto;"></div>
</body>
</html>
.replaceAll("\n","<br/>"))
<br/>被csdn弄成了一个空格
楼主:你要注意啊,replace是不行的!如果我上的代码,你用replace, 只能替换一个回车。所以你一定要用我上面的那个自定义的 replaceAll !!!!!!!!!