如题:通过innerHTML;获得<td>的内容;<td onclick="changejieshu(this)">nihao</td>
 function changejieshu(tatr)
 {
   var txtjieshu=document.getElementById("ctl00_business_txtjieshu");
   txtjieshu.value =tatr.innerHTML;
   alert(txtjieshu.value+"222");
    
 }
为什么 alert(txtjieshu.value+"222");可以看到内容。但在页面textbox却什么也没有//用的asp。net控件

解决方案 »

  1.   


    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" enableSessionState="True" %><html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title>无标题页</title>
        <script type="text/javascript">
             var t = function(obj){
                var txt=document.getElementById("<%=txt.ClientID %>");
                txt.value =obj.innerHTML;
            }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
            <table cellpadding="0" cellspacing="0" class="form" id="table">
                <tr>
                    <td onclick="t(this);">nihao</td>
                </tr>
            </table>
            <asp:TextBox ID="txt" runat="server"></asp:TextBox>
        </form>
    </body>
    </html>可以啊 
      

  2.   

    可是在页面上的TextBox没有内容呀,不会出现“nihao”
      

  3.   

    可以的啊,tatr.innerHTML具体是什么内容?
      

  4.   

                                 <% if (dtt.Rows.Count > 0)
                                       {
                                           %>
                                           <table>
                                           
                                          
                                           <%
                                           for (int i = 0; i < dtt.Rows.Count; i++)
                                           {%>                                      <tr   onclick="changejieshu(this)">
                                          <td > 
                                           
                                           <%Response.Write(dtt.Rows[i]["Sort"].ToString() + ">"    +dtt.Rows[i]["TypeName"].ToString() + ">" + dtt.Rows[i]["class_3_name"].ToString());                                         cl1 = dtt.Rows[i]["parent_id"].ToString(); 
                                             cl2 = dtt.Rows[i]["child_id"].ToString();
                                             cl3 = dtt.Rows[i]["root_id"].ToString();
                                          
                                            
                                           }
                                           %></td></tr>
                                            </table>
                                      <% }
                                     %>
    这就是要取的内容,从数据库里面取出的