.Append("          var sTable=document.createElement(\"table\");   ").Append(Environment.NewLine)//****************表格
        .Append("        sTable.style.margin=\"1em 0\"  ").Append(Environment.NewLine)
        .Append("        sTable.setAttribute(\"id\",\"sTable1\");   ").Append(Environment.NewLine)
        .Append("        var sTr1 = sTable.insertRow(); ").Append(Environment.NewLine) ///////////////////////
        .Append("        var sTd11 = sTr1.insertCell();  ").Append(Environment.NewLine)
        .Append("        sTd11.innerHTML=\"专辑简介:\";   ").Append(Environment.NewLine)
        .Append("        var sTd12 = sTr1.insertCell();  ").Append(Environment.NewLine)
        .Append("        sTd12.innerHTML=\"<asp:TextBox ID=\"TextBox1\" runat=\"server\" Height=\"21px\" Width=\"232px\" > <\\asp:TextBox > ;   ").Append(Environment.NewLine)
        .Append("        var sTr2 = sTable.insertRow(); ").Append(Environment.NewLine)
        .Append("        var sTd21 = sTr2.insertCell();  ").Append(Environment.NewLine)
        .Append("        sTd21.innerHTML=\"专辑简介:\";   ").Append(Environment.NewLine)
        .Append("        var sTd22 = sTr2.insertCell();  ").Append(Environment.NewLine)
        .Append("        sTd22.innerHTML=\"<asp:TextBox ID=\"TextBox2\" runat=\"server\" Height=\"120px\" Width=\"232px\" TextMode=\"MultiLine\" > <\\asp:TextBox > ;   ").Append(Environment.NewLine)
        .Append("        document.getElementById(\"msgDiv\").appendChild(sTable); ").Append(Environment.NewLine)请问下这样的代码生成一个表格:
<table>
        <tr>
        <td>专辑名称:</td>
        <td><asp:TextBox ID="TextBox1" runat="server" Height="21px" Width="232px"></asp:TextBox></td>
        </tr>
        <tr>
        <td style="padding-bottom:80px">专辑简介:</td>
        <td><asp:TextBox ID="TextBox2" runat="server" Height="120px" Width="232px" TextMode="MultiLine"></asp:TextBox></td>
        </tr>
       </table>
有什么问题?现在是本来在后台有个函数可以生成Html代码的(CSS+ js),我加了上面的代码后就什么也不显示了,不知道问题出现在哪?

解决方案 »

  1.   

    你拼接的是字符串,服务器会直接响应到浏览器!所以你的 
    asp:TextBox ID="TextBox2" runat="server" 这些 东西 ,浏览器不认识你自己右键查看源代码,不就知道是这么回事了
      

  2.   

    不清楚你的问题所在,不过<asp:TextBox> 这个控件最终在页面上生成的是<input type="text" />这样的标签,你直接输入<asp:TextBox> ,浏览器应该是不认识的。
      

  3.   

    Append是什么函数?首字母大写的函数命名还是很少见的
      

  4.   

    如果拼接字符串,不可能出现这个<asp:TextBox></asp:TextBox>
    它最终会被浏览器解释成<input>标签
    所以sTd12.innerHTML=\"&lt;input type=\"text\" id=\"text1\" style=\"height:21px; width:232px\" &gt; &lt;")
      

  5.   

    现在的做的是一个用户自定义控件(.NET的),不要管Append什么的,只是拼接下字符串形成脚本而已。出现的问题是拼接的这部分代码没有显示任何东西。
      

  6.   

    测试了,问题出现在:
    .Append("        sTd11.innerHTML=\"专辑名称:\";   ").Append(Environment.NewLine)
            .Append("        var sTd12 = sTr1.insertCell();  ").Append(Environment.NewLine)
            .Append("        sTd12.innerHTML=\"&lt;input type=\"text\" id=\"text1\" runat=\"server\" style=\"height:21px; width:232px\" \\ &gt; \";   ").Append(Environment.NewLine)
            .Append("        var sTr2 = sTable.insertRow(); ").Append(Environment.NewLine)
            .Append("        var sTd21 = sTr2.insertCell();  ").Append(Environment.NewLine)
            .Append("        sTd21.innerHTML=\"专辑简介:\";   ").Append(Environment.NewLine)
            .Append("        var sTd22 = sTr2.insertCell();  ").Append(Environment.NewLine)
            .Append("        sTd22.innerHTML=\"&lt;input type=\"text\" id=\"text2\" runat=\"server\" style=\"height:120px; width:232px\" \\ &gt; \";    ").Append(Environment.NewLine)这里的添加文本框不可以,如果去掉则可以显示
      

  7.   

    这是在查看文件下显示的:
    var sTd11 = sTr1.insertCell();  
            sTd11.innerHTML="专辑名称:";   
            var sTd12 = sTr1.insertCell();  
            sTd12.innerHTML="&lt;input type="text" id="text1" runat="server" style="height:21px; width:232px" \ &gt; ";   
            var sTr2 = sTable.insertRow(); 
            var sTd21 = sTr2.insertCell();  
            sTd21.innerHTML="专辑简介:";   
            var sTd22 = sTr2.insertCell();  
            sTd22.innerHTML="&lt;input type="text" id="text2" runat="server" style="height:120px; width:232px" \ &gt; ";