js生成、删除表格方法
<script language="javascript" type="text/javascript">
var index = 0;
function addplan() {
if (validate2()) {
insert(index);
var text = "";
index++;
text += "<table id='tab' style='width:100%; height;25px;' border='1' cellpadding='0' cellspacing='0'>";
text += "<tr style='height:20px;'>";
text += "<td style='width:90px'>" + (index) + "</td>";
var select1=document.getElementById("DropDownList3");
text += "<td style='width:90px;'><label id='txtbegintime'>" + select1.options[select1.selectedIndex].innerText + "</label></td>";
var select2=document.getElementById("DropDownList2");
text += "<td style='width:90px;'><label id='txtendtime'>" + select2.options[select2.selectedIndex].innerText + "</label></td>";
var select3=document.getElementById("DropDownList1");
text += "<td style='width:90px;'><label id='txtNumber'>" + select3.options[select3.selectedIndex].innerText + "</label></td>";
var select5=document.getElementById("txtNumber1")
text += "<td style='width:90px;'><label id='txtyuPrice'>" +select5.options[select5.selectedIndex].innerText + "</label></td>";
var select4=document.getElementById("txtBianma");
text += "<td style='width:90px;'><label id='txtKCNumber'>" +select4.options[select4.selectedIndex].innerText + "</label></td>";
text += "<td style='width:90px;'><label id='txtPrice'>" + document.getElementById("txtKCNumber1").value + "</label></td>";
text += "<td style='width:90px;'><label id='txtPrice'>" + document.getElementById("txtyuPrice1").value + "</label></td>";
text += "<td style='width:90px;'><label id='txtPrice'>" + document.getElementById("txtPrice1").value + "</label></td>";
text += "<td style='width:90px;'><label id='txtBei'>" + document.getElementById("txtBei1").value + "</label></td>";
//var select6=document.getElementById("ddlscs");
//text +="<td style='width:90px;'><lable id='txtscs'>"+select6.options[select6.selectedIndex].innerText+"</lable></td>";
text +="<td style='width:90px;'><lable id='txtscs'>厂商名称</lable></td>";
text+="<td style='width:90px;'><input type='button' value='删除' onclick='deleteRow(this)'></td>"
text += "<td style='width:90px;'></td>";
text += "</tr></table>";
document.getElementById("div_play1").innerHTML += text;
document.getElementById("txtBianma").value = "";
document.getElementById("txtNumber1").value = "";
document.getElementById("txtKCNumber1").value = "";
document.getElementById("txtyuPrice1").value = "";
document.getElementById("txtPrice1").value = "";
document.getElementById("txtBei1").value = "";
}
}
function insert(index) {
var HTYPE = document.getElementById("DropDownList3").value;
var PRODUCTNAME = document.getElementById("DropDownList2").value;
var PRODUCTTYPE = document.getElementById("DropDownList1").value;
var PRODUCTSBM = document.getElementById("txtNumber1").value;
var PRODUCTSNUMBER = document.getElementById("txtBianma").value;
var PROFUCTSKCNUMBER=document.getElementById("txtKCNumber1").value;
var PRODUCTSPRICE = document.getElementById("txtyuPrice1").value;
var PRODUCTSMONEY = document.getElementById("txtPrice1").value;
var BEIZU=document.getElementById("txtBei1").value;
var text = HTYPE + "," + PRODUCTNAME + "," + PRODUCTTYPE + "," + PRODUCTSBM + "," + PRODUCTSNUMBER + ","+PROFUCTSKCNUMBER+"," + PRODUCTSPRICE + "," + PRODUCTSMONEY+","+BEIZU;
document.getElementById("listvalue").value += text + "@";
}
function deleteRow(index){
var index = index.parentNode.parentNode.rowIndex;
var tab = document.getElementById('tab');
tab.deleteRow(index);
}
function validate2() {
var txtName1 = document.getElementById("DropDownList3").value;
var txtGUIG1 = document.getElementById("txtGUIG1").value;
var txtNumber1 = document.getElementById("txtNumber1").value;
if (txtName1 == "" || txtName1.length == 0) {
alert("物品名称不可以为空!");
return false;
} else if (txtGUIG1 == "" || txtGUIG1.length == 0) {
alert("规格不能为空!");
return false;
} else if (txtNumber1 == "" || txtNumber1.length == 0) {
alert("数量不能为空!");
return false;
} else {
return true;
}
return true;
}
//计算单条记录金额
function SuanQian()
{
var money=document.getElementById("txtyuPrice1").value;
var SL=document.getElementById("txtKCNumber1").value;
var ZQ=money*SL;
document.getElementById("txtPrice1").value=ZQ;
}
</script>