首页 > 代码库 > js 行列操作

js 行列操作


function insertRow() {
var tbl = document.getElementById("tbCarModel");
var rowLen = tbl.childNodes.length;

var newTr = tbl.insertRow(rowLen - 1);
// var newTr = document.createElement("tr");
// tbl.appendChild(newTr);

var td = document.createElement("td");
var temptd = td.cloneNode(1);

newTr.appendChild(temptd);
temptd.appendChild(createCarModel());


temptd = td.cloneNode(1);
newTr.appendChild(temptd);
temptd.appendChild(createNumber());

temptd = td.cloneNode(1);
newTr.appendChild(temptd);
temptd.appendChild(createCarSum());

temptd = td.cloneNode(1);
newTr.appendChild(temptd);
temptd.appendChild(createAddBtn());

}

function removeRow(tbl) {
if (tbl.rows.length > 3)
tbl.deleteRow(tbl.rows.length - 2);
getCarModel();
}
function upRow(tbl) {
var len = tbl.rows.length - 1;
tbl.rows[len].cells[3].firstChild.valuehttp://www.mamicode.com/= "http://www.mamicode.com/删除一行";
}

function createCarModel() {
var text1 = document.createElement("input");
text1.onblur = function () {
if (text1.value.length > 20) {
alert("车型不能大于20");
text1.valuehttp://www.mamicode.com/= "";
return false;
}
}
return text1;
}

function createNumber() {
var text1 = document.createElement("input");
text1.onblur = function () {
if (text1.value.length > 20) {
alert("订单号不能大于20");
text1.valuehttp://www.mamicode.com/= "";
return false;
}
}
return text1;
}
function createCarSum() {
var text1 = document.createElement("input");
text1.onblur = function () {
var reg = new RegExp("^[0-9]*$"); // "^(.)*[0-9]*(.)*$"//"^[0-9]*$"
if (!reg.test(text1.value)) {
alert("请输入数字!");
text1.valuehttp://www.mamicode.com/= "";
}
getCarModel();
}
return text1;
}
function createAddBtn() {
var tbl = document.getElementById("tbCarModel");
var btn1 = document.createElement("input");
btn1.setAttribute("type", "button");
btn1.setAttribute("value", "删除一行");

btn1.onclick = function () {
// if (btn1.value =http://www.mamicode.com/="添加一行") {
GetCarValues();
removeRow(tbl);
// insertRow();
// btn1.setAttribute("value", "删除一行");
// } else {
// if (tbl.rows.length > 2) {

// upRow(tbl);
//// }
}
// }
return btn1;
}

function getCarModel() {
var tbl = document.getElementById("tbCarModel");
var len = tbl.rows.length;
var row;
var ctl;
var result = 0;
var no;
for (var i = 1; i < len - 1; i++) {
row = tbl.rows[i];
ctl = row.cells[2].firstChild;
if (ctl.value =http://www.mamicode.com/="" || ctl.value =http://www.mamicode.com/= null) {
no = 0;
} else {
no = parseInt(ctl.value);
}
result = result + no;
}
document.getElementById("ctl00_PlaceHolderMain_txtCarSum1").value = http://www.mamicode.com/result;
}

 


function GetCarValues() {
var tbl = document.getElementById("tbCarModel");
var len = tbl.rows.length;
var row;
var ctl;
var result = "";
for (var i = 1; i < len - 1; i++) {
row = tbl.rows[i];
ctl = row.cells[0].firstChild;
result += ctl.value + "/";
ctl = row.cells[1].firstChild;
result += ctl.value + "/";
ctl = row.cells[2].firstChild;
result += ctl.value + "$";
}
document.getElementById("ctl00_PlaceHolderMain_hidCarModel").value = http://www.mamicode.com/result;

}
function BindTable() {
var carValue = http://www.mamicode.com/document.getElementById("ctl00_PlaceHolderMain_hidCarModel").value;
var carArray = new Array();

if (carValue != "")
carArray = carValue.split("$");

//添加空行
for (var i = 0; i < carArray.length - 1; i++) {
insertRow();
}

var tbl = document.getElementById("tbCarModel");
var len = tbl.rows.length;
var row;
var ctl;
var result = "";
var car11 = new Array();
for (var i = 1; i < len - 1; i++) {
car11 = carArray[i - 1].split("/");
row = tbl.rows[i];
ctl = row.cells[0].firstChild;
ctl.value = http://www.mamicode.com/car11[0];
ctl = row.cells[1].firstChild;
ctl.value = http://www.mamicode.com/car11[1];
ctl = row.cells[2].firstChild;
ctl.value = http://www.mamicode.com/car11[2];
}
document.getElementById("ctl00_PlaceHolderMain_hidCarModel").value = http://www.mamicode.com/result;

}


function CarModelLoad() {

var objCarType = $("#ctl00_PlaceHolderMain_SelCarType").val();

$("#lblCarType1").html(objCarType);
$("#lblCarType2").html(objCarType);

var objProjectName = $("#ctl00_PlaceHolderMain_SelProjectName").val();
$("#lblProjectName1").html(objProjectName);
$("#lblProjectName2").html(objProjectName);

$("#ctl00_PlaceHolderMain_SelCarType").change(function () {
var objCarType = $("#ctl00_PlaceHolderMain_SelCarType").val();
$("#lblCarType1").html(objCarType);
$("#lblCarType2").html(objCarType);
});

$("#ctl00_PlaceHolderMain_SelProjectName").change(function () {
var objProjectName = $("#ctl00_PlaceHolderMain_SelProjectName").val();

$("#lblProjectName1").html(objProjectName);
$("#lblProjectName2").html(objProjectName);

});
getCarModel();
}

function CheckValidForSave() {

if (IsValueNull(txtReason, "请填写申请原因!"))
return false;
if (IsValueNull(txtCarSum, "请填写申请车辆台数!"))
return false;
if (IsValueNull(txtEndTime, "请填写还款日期!"))
return false;
if (IsValueNull(txtCompanyName, "请填写公司名称!"))
return false;

var carNum1 = document.getElementById("ctl00_PlaceHolderMain_txtCarSum").value;
var carNum2 = document.getElementById("ctl00_PlaceHolderMain_txtCarSum1").value;
if (carNum1 != carNum2) {
alert("填写车辆数量不一致");
return false;
}

var reason = document.getElementById("ctl00_PlaceHolderMain_txtReason").value;

if (reason.length >= 200) {
alert("欠款发车原因过长,请控制在200字以内!");
return false;
}
var reason = document.getElementById("ctl00_PlaceHolderMain_txtCompanyName").value;

if (reason.length > 50) {
alert("公司签名不能大于50");
return false;
}
var date1 = document.getElementById("ctl00_PlaceHolderMain_txtEndTime").value;
var today = getNowFormatDate();
var startDate = new Date(today.replace("-", ",")).getTime();
var endDate = new Date(date1.replace("-", ",")).getTime();

if (startDate > endDate) {
alert("还款时间不能小于申请时间");
return false;
}

GetCarValues();

}

function CheckTable() {
var tbl = document.getElementById("tbCarModel");
var len = tbl.rows.length;
var row;
var ctl;
var result = "";
for (var i = 1; i < len - 1; i++) {
row = tbl.rows[i];
ctl = row.cells[0].firstChild;
result = ctl.value;
if (result == "") {
return false;
}
ctl = row.cells[1].firstChild;
result = ctl.value;
if (result == "") {
return false;
}
}
}