<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <table cellSpacing="0">
    <tr>
    <td id="contain">
    </td>
    </tr>
    </table>
    </form>
</body>
</html>
<script>
   // var contain = document.getElementById('contain');
   
    function CreateTable(rowCount,colCount)
    {
    //debugger;
        var table = document.createElement('<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" ></table>');
        document.getElementById('contain').appendChild(table);
        for (var i = 0; i < rowCount; i++)
        {
             var tr = table.insertRow(-1);
            tr.style.height = '18px';
            tr.id = 'row' + i;
            table.appendChild(tr);
            
            for (var j = 0; j < colCount; j++)
            {
                var td = tr.insertCell(-1) ;
                td.style.width = '18px';
                td.id = 'row' + i + 'cell' + j
               // td.innerHTML = '&nbsp;11';
                td.text = '&nbsp;11';
                tr.appendChild(td);
            }
        }
        
        table.style.borderWidth = '1px';
        table.style.borderColor = 'red';
        table.style.borderStyle = 'solid';
        
        //alert(document.getElementById('contain').outerHTML);
    }
    CreateTable(3, 3);
</script>

解决方案 »

  1.   

    table  后边属性 加个border="1"
      

  2.   

    <html xmlns="http://www.w3.org/1999/xhtml" > 
    <head runat="server"> 
        <title>Untitled Page </title> 
    </head> 
    <body> 
        <form id="form1" runat="server"> 
        <table cellSpacing="0"> 
        <tr> 
        <td id="contain"> 
        </td> 
        </tr> 
        </table> 
        </form> 
    </body> 
    </html> 
    <script> 
      // var contain = document.getElementById('contain'); 
      
        function CreateTable(rowCount,colCount) 
        { 
        //debugger; 
            var table = document.createElement('<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" > <\/table>'); 
            document.getElementById('contain').appendChild(table); 
    tb = document.createElement('tBody');
    table.appendChild(tb);
            for (var i = 0; i < rowCount; i++) 
            { 
                var tr = tb.insertRow(-1); 
                tr.style.height = '18px'; 
                tr.id = 'row' + i; 
                tb.appendChild(tr); 
                
                for (var j = 0; j < colCount; j++) 
                { 
                    var td = tr.insertCell(-1) ; 
                    td.style.width = '18px'; 
                    td.id = 'row' + i + 'cell' + j 
                  // td.innerHTML = '&nbsp;11'; 
                    td.innerText = '&nbsp;11'; 
                    tr.appendChild(td); 
                } 
            } 
            
            table.style.borderWidth = '1px'; 
            table.style.borderColor = 'red'; 
            table.style.borderStyle = 'solid'; 
            
            alert(document.getElementById('contain').outerHTML); 
        } 
        CreateTable(3, 3); 
    </script>
    一个是createElement的东东不用空格
    二个要控制Table要用Tbody
    三个修改TD内文本是innerText(FF是textContent)
      

  3.   

    var table = document.createElement('<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" > <\/table>'); 
    改成
    var table = document.createElement('table')
      

  4.   

    <html> 
    <head> 
        <title>Untitled Page </title> <script> 
      // var contain = document.getElementById('contain'); 
      
        function CreateTable(rowCount,colCount) 
        { 
            var table = document.createElement('<table border=\"1\" cellspacing=\"0\" cellpadding=\"0\" ></table>');          var rowCount=1;
    var rowCount=1;
            for (var i = 0; i < rowCount; i++) 
            { 
                var tr = table.insertRow(-1); 
                //tr.style.height = '38px'; 
                //tr.id = 'row' + i; 
                table.appendChild(tr); 
                
                for (var j = 0; j < colCount; j++) 
                { 
                    var td = tr.insertCell(-1) ; 
                    //td.style.width = '18px'; 
                    //td.id = 'row' + i + 'cell' + j 
    td.innerHTML = '你好'; 
                    //td.text = '你好'; 
                    tr.appendChild(td); 
                } 
            } 
           
            //table.style.borderWidth = '1px'; 
            //table.style.borderColor = 'red'; 
            //table.style.borderStyle = 'solid'; 
             //document.getElementById('contain').appendChild(table); 
    document.getElementById('contain').innerHTML=table.outerHTML;
        } </script>
    </head> 
    <body onload="CreateTable(3,3);"> 
        <form id="form1"> 
        <table cellSpacing="0"> 
        <tr> 
        <td id="contain">1</td> 
        </tr> 
        </table> 
        </form> 
    </body> 
    </html> 
      

  5.   

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Untitled Page </title>
    </head>
    <body>
        <form id="form1" runat="server">
        <table cellSpacing="0" border="1">
            <tr>
              <td id="contain">
             </td>
            </tr>
        </table>
        </form>
    </body>
    </html>
    <script>
      // var contain = document.getElementById('contain');
     
        function CreateTable(rowCount,colCount){
        //debugger;
            var table = document.createElement("table");
    var i,j,tr,td;

    with(table){
    setAttribute("border",1);
    setAttribute("cellspacing",0);
    setAttribute("cellpadding",0);

    style.cssText="border:1px solid red;";
    }

            document.getElementById('contain').appendChild(table);
            for (i = 0; i < rowCount; i++){
                tr = table.insertRow(-1);
                tr.style.height = '18px';
                tr.id = 'row' + i;
                //table.appendChild(tr);
               
                for (j = 0; j < colCount; j++){
                    td = tr.insertCell(-1) ;
                    td.style.width = '18px';
                    td.id = 'row' + i + 'cell' + j
                    td.innerHTML = '&nbsp;'+i+j;
                    tr.appendChild(td);
                }
            }
        }
        CreateTable(3, 3);
    </script>
      

  6.   

     <table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" > </table>'我想你的table的border设为了“0”,而你下面又设置了table.style.borderWidth = '1px';你把table里border属性的值设的大一些应该没问题吧。而且table.style.borderWidth = '1px'  中 1px是不是太小了。要不你把值都设置的大写,免得看不清楚,然后你再看是不是这个地方的原因。
      

  7.   

    我没仔细看你的代码哦,但是不必写的这么麻烦吧?我每次都是一次性加入,懒得去一个个设置td......
    var row = $("partTAB").insertRow(-1);//partTAB : 要增加行的Id
    var col = row.insertCell(-1);
    ...
    row.align="center";
    row.className='content';
    col.innerHTML="<input type='checkbox' name='ckPart'/><input type='hidden' name='impDetail' value='0'>";//选择
    ...