<html>
<head>
<script>
function myclick(td)
{
td.innerHTML='<input type="text" value="test">';
}
</script>
</head>
<body>
<table border=1>
<tr>
<td onclick="myclick(this);">sss</td>
<td>ss</td>
</tr>
</table>
</body>
</html>
为什么我这个text不能编写内容!

解决方案 »

  1.   

    因为你没当onclick就会触发一次myclick方法,你可以看看冒泡或者其他的解决方案,很简单的,你自己查查吧
      

  2.   

    例如:td.innerHTML='<input type="text" value="test" id="a01">';//你给个id用,当然了id要唯一
    document.getElementById("a01").focus();
      

  3.   

    <!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>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <style>
    </style>
    </head><body>
    <script>
    function myclick(td)
    {
    td.innerHTML='<input type="text" value="test" onblur="aa(this)">';
    }function aa(t){
    document.getElementById('t').innerHTML = t.value;
    };
    </script>
    <table border=1>
    <tr>
    <td onclick="myclick(this);" id="t">sss</td>
    <td>ss</td>
    </tr>
    </table></body>
    </html>
      

  4.   

    <html>
    <head>
    <script>
    function myclick(td)
    {
    td.innerHTML='<input type="text" value="test" onclick="stopMe(event);">';
    }function stopMe(e){
    e = e || window.event;
    if(e.stopPropagation){
    e.stopPropagation();
    e.preventDefault();
    }else{
    e.cancelBubble = true;
    e.returnValue = false;
    }
    }</script>
    </head>
    <body>
    <table border=1>
    <tr>
    <td onclick="myclick(this);">sss</td>
    <td>ss</td>
    </tr>
    </table>
    </body>
    </html>
      

  5.   

    楼主的代码没有错,也是可以编写内容的,只是在编写的时候重新触发<td onclick="myclick(this);">,给楼主的感觉就是不能编辑
      

  6.   


    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>演示操作</title>
    </head>
    <body>
    <script language="javascript">
    function myclick(td)
    {
        td.innerHTML='<input type="text" value="test">';
    }
    </script>
    <table border=1>
    <tr>
        <td onfocus="myclick(this);">sss</td>
        <td>ss</td>
    </tr>
    </table>
    </body>
    </html>
      

  7.   

    楼主换成这个事件就能看出了
    onfocus="myclick(this);"
      

  8.   

    你每次点,都触发myclick 事件。你怎么编写内容啊?
      

  9.   

    <html>
    <head>
    <script>
    function myclick(td)
    {
    if(td.getElementsByTagName('input').length>0) return;
    td.innerHTML='<input type="text" value="test">';
    }
    </script>
    </head>
    <body>
    <table border=1>
    <tr>
    <td onclick="myclick(this);">sss</td>
    <td>ss</td>
    </tr>
    </table>
    </body>
    </html>
      

  10.   

    很简单就解决了,创建text之后取消td的点击事件就行了:
    <script>
    function myclick(td)
    {
    td.innerHTML='<input type="text" value="test" />';
    td.onclick="";
    }
    function aa(t){
        document.getElementById('t').innerHTML = t.value;
    };
    </script>
    <table border=1>
    <tr>
    <td onclick="myclick(this);" id="t">sss</td>
    <td>ss</td>
    </tr>
    </table>
      

  11.   

    复制原代码时复制多了,aa()是没用的:<script>
    function myclick(td)
    {
     td.innerHTML='<input type="text" value="test" />';
     td.onclick="";
    }
    </script>
    <table border=1>
    <tr>
    <td onclick="myclick(this);">sss</td>
    <td>theforever_csdn</td>
    </tr>
    </table>