<script>
function createTable()
{
var vTable=document.createElement("table");
vTable.cellPadding="0";
vTable.cellSpacing="0";
vTable.border="1";
vTable.color="#000000";
vTable.borderColorDark="#000000";
vTable.borderColorLight="#FFFFFF";
for(kIndex=0;kIndex<5;kIndex++)
{
var vTr=vTable.insertRow(kIndex);
for(iIndex=0;iIndex<5;iIndex++)
{
vTd=vTr.insertCell(iIndex);
vTd.innerHTML="<input type=text style='border:0px solid'>";
}
}
DivID.appendChild(vTable);
}
function mouseDown()
{
if(event.button==2)
{
if(event.srcElement.tagName=="INPUT")
{
window.confirm(event.srcElement.value);
}
}
}
document.onmousedown=mouseDown;
document.captureEvents(Event.MOUSEDOWN);
</script>
<input type=button value="创建表格" onclick="createTable();">
<div id="DivID"></div>

解决方案 »

  1.   

    <script>
    function addRow() 
    {
        //插入行
        var newRow=tb.insertRow();
        //插入列.
        cell = newRow.insertCell();
        cell.innerText="Cell";
        //设计id
        cell.id = "td1"
    }
    </script>
    <table id="tb" border="1">
    </table>
    <input type=button onclick="addRow()" value="addRow">
    <input type=button onclick="alert(td1.innerText)" value="Get td1">