如何单击“生成”按钮以后,将变量S中的内容现实在文本框中????
我是JS的初学者,对这方面不是很懂,所以请教各位高手啊!!!
代码如下:
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>新建网页 1</title>
</head><body bgcolor=#FFFFFF><SCRIPT LANGUAGE="JavaScript">
<!--
var mm={};
mm["1001"] = {mMoney:5, mStr:"皇品叉烧饭"}
mm["1005"] = {mMoney:8, mStr:"台湾香肠饭"}
mm["1006"] = {mMoney:8, mStr:"特制招牌饭"}
mm["1007"] = {mMoney:9, mStr:"鲁味肉燥饭"}
//mm["1008"] = {mMoney:9}var s="<table border='1'>";
s+="<tr bgcolor='#008844'>";
//s+="<td>序号</td>";
s+="<td>菜单</td>";
s+="<td>价格</td>";
s+="</tr>";
for(var i in mm)
{
  s+="<tr>";
  //s+="<td>"+ i +"</td>";
  s+="<td>"+ mm[i].mStr +"</td>";
  s+="<td>"+ mm[i].mMoney +"</td>";  s+="</tr>";
}
s+="</table>";//document.write(s);s+="<input type='button' value='白色' onclick=document.bgColor='#FFFFFF' name='b1'>"
s+="<input type='button' value='绿色' onclick=document.bgColor='#00FF00' name='b2'>"
s+="<input type='button' value='黄色' onclick=document.bgColor='#FFFF00' name='b3'>"
s+="<input type='button' value='黑色' onclick=document.bgColor='#000000' name='b4'>"-->
</SCRIPT>
<textarea name="t1" rows="6" cols="40">
</textarea>
<input type="button" value="生成" onclick=document.write(s)>
</body></html>

解决方案 »

  1.   

    <!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>
        <title>Untitled Page</title>
        <script language="javascript" type="text/javascript">
    function sss()
    {
    var mm={};
    mm["1001"] = {mMoney:5, mStr:"皇品叉烧饭"}
    mm["1005"] = {mMoney:8, mStr:"台湾香肠饭"}
    mm["1006"] = {mMoney:8, mStr:"特制招牌饭"}
    mm["1007"] = {mMoney:9, mStr:"鲁味肉燥饭"}
    //mm["1008"] = {mMoney:9}var s="<table border='1'>";
    s+="<tr bgcolor='#008844'>";
    //s+="<td>序号</td>";
    s+="<td>菜单</td>";
    s+="<td>价格</td>";
    s+="</tr>";
    for(var i in mm)
    {
      s+="<tr>";
      //s+="<td>"+ i +"</td>";
      s+="<td>"+ mm[i].mStr +"</td>";
      s+="<td>"+ mm[i].mMoney +"</td>";  s+="</tr>";
    }
    s+="</table>";//document.write(s);s+="<input type='button' value='白色' onclick=document.bgColor='#FFFFFF' name='b1'>"
    s+="<input type='button' value='绿色' onclick=document.bgColor='#00FF00' name='b2'>"
    s+="<input type='button' value='黄色' onclick=document.bgColor='#FFFF00' name='b3'>"
    s+="<input type='button' value='黑色' onclick=document.bgColor='#000000' name='b4'>"
    document.getElementById("t2").value = s ;
    }</script></head>
    <body>
    <textarea name="t1" id="t2" rows="6" cols="40">
    </textarea>
    <input type="button"  value="生成" onclick="sss()"/>
    </body>
    </html>
      

  2.   

    document.getElementById("t2").value = s ;