刚学ajax,遇到一个奇怪的问题,textarea内容无法用javascript”打印“ - Web 开发 / Ajax
问题是这样的,我用ajax做一个发站内短信的东东,但是那个短信内容用始终显示不出来,在postNewMsg()函数中,能够检查到msgcontent是否填写了,如果没有填写,函数的alert能正常提示工作,但是getInfo( "message.asp?msg_action=postnewmsg&msgtouser= "+msgtouser.value+ "&msgtitle= "+msgtitle.value+ "&msgcontent= "+msgcontent.value+ " ");这句话中,msgcontent无法传递给message.asp(其他参数都传过去了)。后来我又加了一句测试的语句就是
document.getElementById( "my_main ").innerHTML =msgcontent.value;这句话也死活不正常,如果是表单中的其他元素,上一句则能正常显示比如document.getElementById( "my_main ").innerHTML =msgtouser.value; 就能显示你在表单中填写的收件人。我实在搞不懂为什么msgcontent不行,而其他表单元素就行啊??高人指点迷津啊!!!
*******************************
<form id= "newmsgform " name= "newmsgform " onSubmit= "return false; ">
<table width= "610 " border= "0 " cellpadding= "0 " cellspacing= "1 " bgcolor= "#AEDF47 ">
<tr class= "a1 ">
<td height= "25 " colspan= "2 "> <div align= "center " class= "a1 "> 发短信(请输入完整信息) </div> </td>
</tr>
<tr>
<td width= "84 " height= "25 " bgcolor= "#FFFFFF "> <span style= "font-weight: bold "> 收件人: </span> </td>
<td width= "523 " bgcolor= "#FFFFFF "> <input type=text name= "msgtouser " value= " <%=request( "msgtouser ")%> " size=50>
<SELECT name=touser onChange= "DoTitle(this.options[this.selectedIndex].value); ">
<OPTION selected value= " "> 选择 </OPTION>
<%dim rs,sql
set rs=server.createobject( "adodb.recordset ")
sql= "select userrealname from [user] order by userid desc "
rs.open sql,conn,1,1
do while not rs.eof
%>
<OPTION value= " <%=rs(0)%> "> <%=rs(0)%> </OPTION>
<%
rs.movenext
loop
rs.close
set rs=nothing
%>
</SELECT> </td>
</tr>
<tr>
<td height= "25 " bgcolor= "#FFFFFF "> <span style= "font-weight: bold "> 主 题: </span> </td>
<td bgcolor= "#FFFFFF "> <input name= "msgtitle " type= "text " size= "60 " maxlength= "50 "> </td>
</tr>
<tr>
<td height= "25 " valign= "top " bgcolor= "#FFFFFF "> <span style= "font-weight: bold "> <br>
内 容: </span> </td>
<td bgcolor= "#FFFFFF "> <textarea name= "msgcontent " cols= "60 " rows= "10 " > </textarea> </td>
</tr>
<tr>
<td height= "25 " colspan= "2 " valign= "top " bgcolor= "#FFFFFF "> <span style= "font-weight: bold "> <br>
说 明: <br>
</span> ① 可以用英文状态下的逗号将用户名( <span style= "font-weight: bold "> 注意:是真实姓名 </span> )隔开实现群发 <BR>
② 标题最多50个字符,内容最多500个字符
<span style= "font-weight: bold "> <BR>
</span> </td>
</tr>
<tr>
<td height= "25 " colspan= "2 " bgcolor= "#FFFFFF "> <div align= "center ">
<input type= "submit " name= "send " value= "发送 " onclick= "postNewMsg(); ">
<input type= "submit " name= "save " value= "保存 ">
<input type= "reset " name= "clear " value= "清除 ">
</div> </td>
</tr>
</table>
</form>
********************************************************************
function postNewMsg() //处理提交
{
var msgtouser=document.getElementById( "msgtouser ")
var msgtitle=document.getElementById( "msgtitle ");
var msgcontent=document.getElementById( "msgcontent ")
if (msgtouser.value== " ")
{
alert( "收件人不可为空! ");
return false;
}
if (msgtitle.value== " ")
{
alert( "主题不可为空! ");
return false;
}
if (msgcontent.value== " ")
{
alert( "短信内容不可为空! ");
return false;
}
document.getElementById( "my_main ").innerHTML = "正在发送短信... ";
document.getElementById( "my_main ").innerHTML =msgcontent.value;
//getInfo( "message.asp?msg_action=postnewmsg&msgtouser= "+msgtouser.value+ "&msgtitle= "+msgtitle.value+ "&msgcontent= "+msgcontent.value+ " ");
}
[解决办法]
把msgcontent.value替换成 escape(msgcontent.value) 试试