//全选
function checkAll(target) {
var checkeds = document.getElementsByName("b_id");
for (var i = 0; i < checkeds.length; i++) {
checkeds[i].checked = target.checked;
}
}
function checkAll1(target) {
var checkeds = document.getElementsByName("b_id1");
for (var i = 0; i < checkeds.length; i++) {
checkeds[i].checked = target.checked;
}
}
//刷新行号
function refreshRowNo() {
var tbody = $("tbody");
for (var i = 0; i < tbody.rows.length; i++) {
tbody.rows[i].cells[0].innerHTML = i + 1;
}
}
function refreshRowNo1() {
var tbody = $("tbody1");
for (var i = 0; i < tbody.rows.length; i++) {
tbody.rows[i].cells[0].innerHTML = i + 1;
}
}
//添加行
function AddRow() {
var tbody = $("tbody");
var row = tbody.insertRow(tbody.rows.length);
row.insertCell(row.cells.length);
row.insertCell(row.cells.length).innerHTML = '<input type="checkbox" name="b_id" style="text-align: center"/>';
row.insertCell(row.cells.length).innerHTML = '<textarea style="height: 99px; width: 86px" name="name" />';
row.insertCell(row.cells.length).innerHTML = '<textarea style="height: 99px; width: 350px" name="number" />';
row.insertCell(row.cells.length).innerHTML = '<textarea style="height: 99px; width: 350px" name="price" />';
row.insertCell(row.cells.length).innerHTML = '<textarea style="height: 99px; width: 180px" name="sum" />';
row.insertCell(row.cells.length).innerHTML = '<textarea style="height: 99px; width: 180px" name="beizhu" />';
refreshRowNo();
}
function AddRow1() {
var tbody = $("tbody1");
var row = tbody.insertRow(tbody.rows.length);
row.insertCell(row.cells.length);
row.insertCell(row.cells.length).innerHTML = '<input type="checkbox" name="b_id1" style="text-align: center"/>';
row.insertCell(row.cells.length).innerHTML = '<textarea style="height: 99px; width: 86px" name="name1" />';
row.insertCell(row.cells.length).innerHTML = '<textarea style="height: 99px; width: 350px" name="number1" />';
row.insertCell(row.cells.length).innerHTML = '<textarea style="height: 99px; width: 350px" name="price1" />';
row.insertCell(row.cells.length).innerHTML = '<textarea style="height: 99px; width: 180px" name="sum1" />';
row.insertCell(row.cells.length).innerHTML = '<textarea style="height: 99px; width: 180px" name="beizhu1" />';
refreshRowNo1();
}
//删除行
function DelRow() {
var checkeds = document.getElementsByName("b_id");
var ischeck = false;
for (var i = checkeds.length - 1; i >= 0; i--) {
if (checkeds[i].checked) {
ischeck = true;
break;
}
}
if (ischeck) {
if (confirm("确定删除选中行?")) {
for (var i = checkeds.length - 1; i >= 0; i--) {
if (checkeds[i].checked) {
var index = checkeds[i].parentNode.parentNode.rowIndex;
$("tbody").deleteRow(index - 1);
}
}
refreshRowNo();
}
} else {
alert("请选中需要删除的行!");
}
}
function DelRow1() {
var checkeds = document.getElementsByName("b_id1");
var ischeck = false;
for (var i = checkeds.length - 1; i >= 0; i--) {
if (checkeds[i].checked) {
ischeck = true;
break;
}
}
if (ischeck) {
if (confirm("确定删除选中行?")) {
for (var i = checkeds.length - 1; i >= 0; i--) {
if (checkeds[i].checked) {
var index = checkeds[i].parentNode.parentNode.rowIndex;
$("tbody1").deleteRow(index - 1);
}
}
refreshRowNo();
}
} else {
alert("请选中需要删除的行!");
}
}
//保存
function Save() {
var detail = [],
tbody = $("tbody");
for (var i = 0; i < tbody.rows.length; i++) {
var name = tbody.rows[i].cells[2].childNodes[0].value;
var number = tbody.rows[i].cells[3].childNodes[0].value;
var price = tbody.rows[i].cells[4].childNodes[0].value;
var sum = tbody.rows[i].cells[5].childNodes[0].value;
var item = name + "^" + number + "^" + price + "^" + sum;
detail.push(item);
}
var detailstr = detail.join("|");
alert(detailstr)
$("detail").value = detailstr;