一次添一行我会,怎么循环添加就失败了呢?
<script type="text/javascript">
window.onload =function()
{
var num = document.form1.num.value;
var prod = document.form1.prod.value;
var product = prod.split(",");
var newTr = myProduct.insertRow();
newTr.className = "ListItemStyle";
for(int i=0;i<num;i++)
{
//添加5列
var newTd0 = newTr.insertCell();   
var newTd1 = newTr.insertCell();   
var newTd2 = newTr.insertCell();   
var newTd3 = newTr.insertCell();
var newTd4 = newTr.insertCell();
//设置列内容和属性
var j = i*5;
newTd0.innerText = product[j];
newTd1.innerText = product[j+1];
newTd2.innerText = product[j+2];
newTd3.innerText = product[j+3];
newTd4.innerText = product[j+4];
}
}
</script>

解决方案 »

  1.   

    for(int i=0;i<num;i++)
      

  2.   

    我把int改成var以后,是添加行了,但是没有一行行的添加,而已直接添加到第2行后面去了,表格都变形了啊
      

  3.   

    你的prod什么个什么样的  。你用字符串表示先看看 。
      

  4.   

    prod是:TS,衬衣,1,3980,3980,WT,外套,1,5980,5980
    没错啊,1行5个
      

  5.   

    我想表格显示为:
    TS,衬衣,1,3980,3980
    WT,外套,1,5980,5980结果咋么成TS,衬衣,1,3980,3980,WT,外套,1,5980,5980了啊
      

  6.   

    搞定了,加上:
    if(i>0)
    {
    newTr = myProduct.insertRow(i+1);
    newTr.className = "ListItemStyle";
    }
    就好了
      

  7.   

    var newTr = myProduct.insertRow();
    newTr.className = "ListItemStyle";这两行 放到for里面 。