赋值的textarea能分行显示吗?

好好小妖 2008-12-23 09:00:07
textarea通过赋值的方式显示内容,能分行显示吗?
例如 CS文件里动态加载了几个层,层上有textarea,内容从数据库中读取的
sSBInfo=str1+"\n"+str2; //str1 str2存储从数据库中读取的值

strImg+=" <div style=\"LEFT:"+m+"px;TOP:"+n+"px;POSITION: absolute;VISIBILITY: visible;\"> <textarea id='sbxx'runat='server' style='overflow-y:hidden;VISIBILITY: visible;width:150px;height:80px;' onmousemove=\"this.value='"+sSBInfo+"';\" > </textarea> </div>";
为什么不能分行显示啊?我用string s=sSBInfo.Replace("\n","</br>");方式也不行

...全文
121 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
好好小妖 2008-12-25
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 rejoice123 的回复:]
这样也可以显示:


string strInfo = "test1" + "@" + "test2";
int m = 10;
int n = 10;
aa = " <div style=\"LEFT:" + m + "px;TOP:" + n + "px;POSITION: absolute;VISIBILITY: visible;\"> <textarea id=\"TextArea2\" runat=\"server\" style=\"VISIBILITY: visible;width:150px;height:80px;\" wrap=\"hard\" onmousemove=\"mouseover('" + strInfo + "')\" > </textarea> <…
[/Quote]

@代表什么啊,如果string strInfo = "test1" + "@" + "test2"+"@" + "test3"; 则只有test1 和test2能换行,test2和test3不能换行@会显示出来
好好小妖 2008-12-23
  • 打赏
  • 举报
回复
有大侠在吗?
好好小妖 2008-12-23
  • 打赏
  • 举报
回复
如果sSBInfo放在<textarea></textarea>中间则\r\n能换行,即<textarea>"+sSBInfo+"</textarea>方式,
但是我的sSBInfo是放在<textarea onmousemove=\"this.value='"+sSBInfo+"';\" > </textarea>处,用\r\n则会出现网页错误,而用<br>也不行
好好小妖 2008-12-23
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 changke18 的回复:]
sSBInfo=str1+"\r\n"+str2;
[/Quote]

我用\r\n试了,textarea里的内容都显示不出来了,我的textarea是放在DIV里的
西安风影 2008-12-23
  • 打赏
  • 举报
回复
sSBInfo=str1+"\r\n"+str2;
阿云ivan 2008-12-23
  • 打赏
  • 举报
回复
不用换成<br>,他认\r\n
空心兜兜 2008-12-23
  • 打赏
  • 举报
回复
UP
Jack123 2008-12-23
  • 打赏
  • 举报
回复
这样也可以显示:


string strInfo = "test1" + "@" + "test2";
int m = 10;
int n = 10;
aa = "<div style=\"LEFT:" + m + "px;TOP:" + n + "px;POSITION: absolute;VISIBILITY: visible;\"> <textarea id=\"TextArea2\" runat=\"server\" style=\"VISIBILITY: visible;width:150px;height:80px;\" wrap=\"hard\" onmousemove=\"mouseover('" + strInfo + "')\" > </textarea> </div>";
Label1.Text = aa;

-----------------------------------------


function mouseover(t)
{
t=t.replace('@','\r\n');
document.getElementById("TextArea2").value=t;

}
</script>
Jack123 2008-12-23
  • 打赏
  • 举报
回复
这样可以显示:


string strInfo = "test1" + "" + "test2";
int m = 10;
int n = 10;
aa = "<div style=\"LEFT:" + m + "px;TOP:" + n + "px;POSITION: absolute;VISIBILITY: visible;\"> <textarea id=\"TextArea2\" runat=\"server\" style=\"VISIBILITY: visible;width:150px;height:80px;\" onmousemove=\"mouseover('" + strInfo + "')\" > </textarea> </div>";
Label1.Text = aa;
-------------------------------------------------

<script type="text/javascript">
function mouseover()
{
var str="sdfsd\r\nsdfsfds";
document.getElementById("TextArea2").value=str;
}
</script>





好好小妖 2008-12-23
  • 打赏
  • 举报
回复
郁闷中!就是显示不出来
好好小妖 2008-12-23
  • 打赏
  • 举报
回复
如果我的代码写在JS里6楼的方法可以,可是我的代码是写在.cs文件里的,而sSBInfo=str1+"\r\n"+str2;放在<textarea onmousemove="+sSBInfo+"></textarea>会出现网页错误

huxuanhui 2008-12-23
  • 打赏
  • 举报
回复
路过 学习
toury 2008-12-23
  • 打赏
  • 举报
回复
<pre><textarea> </textarea></pre>
这样试下
wangruibaobei 2008-12-23
  • 打赏
  • 举报
回复

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
<script type="text/javascript">
function mouseover()
{
var str="sdfsd\r\nsdfsfds";
document.getElementById("TextArea1").value=str;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<textarea id="TextArea1" runat="server" cols="20" rows="2" onmouseover="mouseover()"></textarea>
</div>
</form>
</body>
</html>

87,910

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧