一次添一行我会,怎么循环添加就失败了呢?
<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>
<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行5个
TS,衬衣,1,3980,3980
WT,外套,1,5980,5980结果咋么成TS,衬衣,1,3980,3980,WT,外套,1,5980,5980了啊
if(i>0)
{
newTr = myProduct.insertRow(i+1);
newTr.className = "ListItemStyle";
}
就好了
newTr.className = "ListItemStyle";这两行 放到for里面 。