js 动态增加行删除行 兼容火狐和IE

<!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=gb2312" />
<title></title>
</head>

<script language="JavaScript">
function insertRow() {
    var num=0;
    for(num=0;num<10;num++){
        var x=document.getElementById('myTable');
        var nowrow = x.rows.length;
        if(nowrow < 101){
            var i = nowrow-1;
            var oneRow = x.insertRow(nowrow);
            var h1=oneRow.insertCell(0);
            var h2=oneRow.insertCell(1);
            var h3=oneRow.insertCell(2);
            var h4=oneRow.insertCell(3);
            var h5=oneRow.insertCell(4);
           
            h1.innerHTML = '<th>'+nowrow+'</th>';
            h2.innerHTML = "<input type='text' class='inputtext_style w81' style='ime-mode:disabled;' id='code' name='code' value='' maxlength='3'>";
            h3.innerHTML = "<span style='display:block;' id='spansku'><input type='text' id='skuid0' style='ime-mode:disabled;' maxlength='7'></span>"
            h4.innerHTML = "<input id='count' type='text' style='ime-mode:disabled;' class='inputtext_style w43' maxlength='4'>";
            h5.innerHTML = "<input id='comment' type='text' style='ime-mode:inactive;' maxlength='40'><input type='hidden' id='sku_id_search'>";
            h1.bgColor = '#E4F1F9';
        }
    }
}

function deleteRow() {
	U= document.getElementById("myTable").rows.length-1;
	if(U>0){
		document.getElementById("myTable").deleteRow(U);
	} else{
		alert("最少保留一行") ;
	}
}

</script>
<form name="myForm">
<table id="myTable" border=1>
<tr οnclick="getIndex()">
	<tr>
        <th> </th>
        <th>カタログ<br />コード</th>
        <th>商品お申込番号</th>
        <th>数量</th>
        <th>コメント</th>
    </tr>
  	<tr>
		<th>1</th>
		<td><input type="text" style="ime-mode:disabled;" value="" id="code" name="code" maxlength="3"></td>
		<td><span style='display:block;' id='spansku'><input type='text' id='skuid0' style='ime-mode:disabled;' maxlength='7'></span></td>
		<td><input id='count' type='text' style='ime-mode:disabled;' class='inputtext_style w43' maxlength='4'></td>
		<td><input id='comment' type='text' style='ime-mode:inactive;' maxlength='40'><input type='hidden' id='sku_id_search'></td>
	</tr>
  	<tr>
		<th>2</th>
		<td><input type="text" style="ime-mode:disabled;" value="" id="code" name="code" maxlength="3"></td>
		<td><span style='display:block;' id='spansku'><input type='text' id='skuid0' style='ime-mode:disabled;' maxlength='7'></span></td>
		<td><input id='count' type='text' style='ime-mode:disabled;' class='inputtext_style w43' maxlength='4'></td>
		<td><input id='comment' type='text' style='ime-mode:inactive;' maxlength='40'><input type='hidden' id='sku_id_search'></td>
	</tr>
  	<tr>
		<th>3</th>
		<td><input type="text" style="ime-mode:disabled;" value="" id="code" name="code" maxlength="3"></td>
		<td><span style='display:block;' id='spansku'><input type='text' id='skuid0' style='ime-mode:disabled;' maxlength='7'></span></td>
		<td><input id='count' type='text' style='ime-mode:disabled;' class='inputtext_style w43' maxlength='4'></td>
		<td><input id='comment' type='text' style='ime-mode:inactive;' maxlength='40'><input type='hidden' id='sku_id_search'></td>
	</tr>
  	<tr>
		<th>4</th>
		<td><input type="text" style="ime-mode:disabled;" value="" id="code" name="code" maxlength="3"></td>
		<td><span style='display:block;' id='spansku'><input type='text' id='skuid0' style='ime-mode:disabled;' maxlength='7'></span></td>
		<td><input id='count' type='text' style='ime-mode:disabled;' class='inputtext_style w43' maxlength='4'></td>
		<td><input id='comment' type='text' style='ime-mode:inactive;' maxlength='40'><input type='hidden' id='sku_id_search'></td>
	</tr>
  	<tr>
		<th>5</th>
		<td><input type="text" style="ime-mode:disabled;" value="" id="code" name="code" maxlength="3"></td>
		<td><span style='display:block;' id='spansku'><input type='text' id='skuid0' style='ime-mode:disabled;' maxlength='7'></span></td>
		<td><input id='count' type='text' style='ime-mode:disabled;' class='inputtext_style w43' maxlength='4'></td>
		<td><input id='comment' type='text' style='ime-mode:inactive;' maxlength='40'><input type='hidden' id='sku_id_search'></td>
	</tr>
  	<tr>
		<th>6</th>
		<td><input type="text" style="ime-mode:disabled;" value="" id="code" name="code" maxlength="3"></td>
		<td><span style='display:block;' id='spansku'><input type='text' id='skuid0' style='ime-mode:disabled;' maxlength='7'></span></td>
		<td><input id='count' type='text' style='ime-mode:disabled;' class='inputtext_style w43' maxlength='4'></td>
		<td><input id='comment' type='text' style='ime-mode:inactive;' maxlength='40'><input type='hidden' id='sku_id_search'></td>
	</tr>
  	<tr>
		<th>7</th>
		<td><input type="text" style="ime-mode:disabled;" value="" id="code" name="code" maxlength="3"></td>
		<td><span style='display:block;' id='spansku'><input type='text' id='skuid0' style='ime-mode:disabled;' maxlength='7'></span></td>
		<td><input id='count' type='text' style='ime-mode:disabled;' class='inputtext_style w43' maxlength='4'></td>
		<td><input id='comment' type='text' style='ime-mode:inactive;' maxlength='40'><input type='hidden' id='sku_id_search'></td>
	</tr>
  	<tr>
		<th>8</th>
		<td><input type="text" style="ime-mode:disabled;" value="" id="code" name="code" maxlength="3"></td>
		<td><span style='display:block;' id='spansku'><input type='text' id='skuid0' style='ime-mode:disabled;' maxlength='7'></span></td>
		<td><input id='count' type='text' style='ime-mode:disabled;' class='inputtext_style w43' maxlength='4'></td>
		<td><input id='comment' type='text' style='ime-mode:inactive;' maxlength='40'><input type='hidden' id='sku_id_search'></td>
	</tr>
  	<tr>
		<th>9</th>
		<td><input type="text" style="ime-mode:disabled;" value="" id="code" name="code" maxlength="3"></td>
		<td><span style='display:block;' id='spansku'><input type='text' id='skuid0' style='ime-mode:disabled;' maxlength='7'></span></td>
		<td><input id='count' type='text' style='ime-mode:disabled;' class='inputtext_style w43' maxlength='4'></td>
		<td><input id='comment' type='text' style='ime-mode:inactive;' maxlength='40'><input type='hidden' id='sku_id_search'></td>
	</tr>
  	<tr>
		<th>10</th>
		<td><input type="text" style="ime-mode:disabled;" value="" id="code" name="code" maxlength="3"></td>
		<td><span style='display:block;' id='spansku'><input type='text' id='skuid0' style='ime-mode:disabled;' maxlength='7'></span></td>
		<td><input id='count' type='text' style='ime-mode:disabled;' class='inputtext_style w43' maxlength='4'></td>
		<td><input id='comment' type='text' style='ime-mode:inactive;' maxlength='40'><input type='hidden' id='sku_id_search'></td>
	</tr>
</table>
<input type="button" οnclick="deleteRow()" value="减少一行">
<input type="button" οnclick="insertRow()" value="增加十行" >
</form> 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值