editview.js
2021-07-01 21:07
标签:checked blank 0.00 value elb submit style div lock editview.js 标签:checked blank 0.00 value elb submit style div lock 原文地址:http://www.cnblogs.com/yueyuepeng/p/7131792.html//***************************************************************
// CMSCSoft JavascriptCore By TableEdit
//***************************************************************
CMSC.TableEdit = function(tablesrc) {
var tableEdit = new Object();
tableEdit.Table = CMSC.$$(tablesrc);
tableEdit.TableRows = tableEdit.Table.rows.length - 1;
tableEdit.TableCells = tableEdit.Table.rows[0].cells.length - 3;
tableEdit.RowIndex = -1;
tableEdit.CellIndex = -1;
tableEdit.FocusFlag = -1;
tableEdit.ListRows = 8;
//屏蔽按键动作
document.onkeydown = function(event) {
event = event || window.event;
switch (event.keyCode) {
case 37: return false; break;
case 38: return false; break;
case 39: return false; break;
case 40: return false; break;
}
};
tableEdit.keyMove = function(event) {
event = event || window.event;
var src = event.srcElement || event.target;
var row = src.parentElement.parentElement;
var cell = src.parentElement;
var cellLeft = cell.cellIndex - 1;
var cellRight = cell.cellIndex + 1;
if (cellLeft ;
if (cellRight >= tableEdit.TableCells + 2) cellRight = tableEdit.TableCells + 2;
var rowUp = row.rowIndex - 1;
var rowDown = row.rowIndex + 1;
if (rowUp ;
if (rowDown >= tableEdit.Table.rows.length - 2) rowDown = tableEdit.Table.rows.length - 2;
var ccell = null;
switch (event.keyCode) {
case 37: ccell = tableEdit.Table.rows[row.rowIndex].cells[cellLeft]; break;
case 38: ccell = tableEdit.Table.rows[rowUp].cells[cell.cellIndex]; break;
case 39: ccell = tableEdit.Table.rows[row.rowIndex].cells[cellRight]; break;
case 40: ccell = tableEdit.Table.rows[rowDown].cells[cell.cellIndex]; break;
}
if (ccell != null) {
ccell.getElementsByTagName("INPUT")[0].select();
}
};
tableEdit.focusCell = function(event , flag) {
event = event || window.event;
var src = event.srcElement || event.target;
var row = src.parentElement.parentElement;
var cell = src.parentElement;
if (tableEdit.RowIndex >= 0 && tableEdit.CellIndex >= 0 && tableEdit.FocusFlag >= 0) {
var pcell = tableEdit.Table.rows[tableEdit.RowIndex].cells[tableEdit.CellIndex];
var pinput = pcell.getElementsByTagName("INPUT")[0];
var pbtn = CMSC.$$("Ico_" + pinput.id);
if (tableEdit.FocusFlag == 1) { pinput.className = "tinput"; }
pbtn.style.display = "none";
}
tableEdit.RowIndex = row.rowIndex;
tableEdit.CellIndex = cell.cellIndex;
tableEdit.FocusFlag = flag;
var cbtn = CMSC.$$("Ico_" + src.id);
if (tableEdit.FocusFlag == 1) { src.className = "oinput"; }
cbtn.style.display = "inline-block";
src.focus();
};
tableEdit.getNewRow = function() {
var newrow = 0;
for (var i = 1; i ) {
var selbox = tableEdit.Table.rows[i].cells[1].getElementsByTagName("INPUT")[0];
var rowno = selbox.value;
var ischeck = parseInt(CMSC.$$("RowCheck_" + rowno).value);
if (ischeck == -1) {
newrow = rowno;
break;
}
}
if (newrow == 0) {
tableEdit.addBlankRows();
newrow = tableEdit.ListRows;
}
return newrow;
};
tableEdit.sumEventRow = function(event) {
event = event || window.event;
var src = event.srcElement || event.target;
var rowsrc = src.parentElement.parentElement;
var rowcell = rowsrc.cells[1];
var row = rowcell.getElementsByTagName("INPUT")[0].value;
if (parseInt(CMSC.$$("RowCheck_" + row).value) >= 0) {
if (fnExist("sumrow")) sumrow(row);
}
};
tableEdit.selectAllRows = function(event) {
event = event || window.event;
var src = event.srcElement || event.target;
var selflag = src.checked;
for (var i = 1; i ) {
var selbox = tableEdit.Table.rows[i].cells[1].getElementsByTagName("INPUT")[0];
selbox.checked = selflag;
}
};
tableEdit.delSelectRows = function() {
if (confirm("确认要将选中的行删除吗?")) {
var drow = 0;
for (var i = 1; i ) {
var selbox = tableEdit.Table.rows[i].cells[1].getElementsByTagName("INPUT")[0];
tableEdit.Table.rows[i].cells[2].innerText = i;
if (selbox.checked) {
tableEdit.Table.deleteRow(i);
drow++;
i--;
}
}
if (drow > 0 && fnExist("sumtotal")) sumtotal();
}
};
tableEdit.addBlankRows = function() {
tableEdit.ListRows = tableEdit.ListRows + 1;
addNewRow(tableEdit.Table.rows.length - 1, tableEdit.ListRows);
if (fnExist("sumtotal")) sumtotal();
};
tableEdit.checkEditRow = function(row) {
var chk = checkRow(row);
if (chk == 0 && fnExist("checkrow")) { if (!checkrow(row)) chk = 1; }
if (chk == 0) {
CMSC.$$("Row_" + row).innerHTML = ‘‘;
} else if (chk == 1) {
CMSC.$$("Row_" + row).innerHTML = ‘‘;
} else {
CMSC.$$("Row_" + row).innerHTML = ‘ ‘;
}
CMSC.$$("RowCheck_" + row).value = chk;
};
tableEdit.submitCheck = function() {
var isok = true;
var submitRows = "";
for (var i = 1; i ) {
var selbox = tableEdit.Table.rows[i].cells[1].getElementsByTagName("INPUT")[0];
var rowno = selbox.value;
var ischeck = parseInt(CMSC.$$("RowCheck_" + rowno).value);
if (ischeck == 1) {
isok = false;
break;
}
}
return isok;
};
tableEdit.submitRows = function() {
var j = 0;
var submitRows = "";
for (var i = 1; i ) {
var selbox = tableEdit.Table.rows[i].cells[1].getElementsByTagName("INPUT")[0];
var rowno = selbox.value;
var ischeck = parseInt(CMSC.$$("RowCheck_" + rowno).value);
if (ischeck == 0) {
if (j > 0) submitRows = submitRows + ",";
submitRows = submitRows + rowno;
j++;
}
}
return submitRows;
};
tableEdit.checkNumber = function(src) {
var filter = /^-?\d+\.?\d{0,8}$/;
if (filter.test(src.value)) {
var val = parseFloat(src.value);
src.value = val.toFixed(0);
} else {
src.value = "0";
}
};
tableEdit.checkFloat1 = function(src) {
var filter = /^-?\d+\.?\d{0,8}$/;
if (filter.test(src.value)) {
var val = parseFloat(src.value);
src.value = val.toFixed(1);
} else {
src.value = "0.0";
}
};
tableEdit.checkFloat2 = function(src) {
var filter = /^-?\d+\.?\d{0,8}$/;
if (filter.test(src.value)) {
var val = parseFloat(src.value);
src.value = val.toFixed(2);
} else {
src.value = "0.00";
}
};
tableEdit.checkFloat3 = function(src) {
var filter = /^-?\d+\.?\d{0,8}$/;
if (filter.test(src.value)) {
var val = parseFloat(src.value);
src.value = val.toFixed(3);
} else {
src.value = "0.000";
}
};
tableEdit.checkFloat4 = function(src) {
var filter = /^-?\d+\.?\d{0,8}$/;
if (filter.test(src.value)) {
var val = parseFloat(src.value);
src.value = val.toFixed(4);
} else {
src.value = "0.0000";
}
};
tableEdit.checkFloat5 = function(src) {
var filter = /^-?\d+\.?\d{0,8}$/;
if (filter.test(src.value)) {
var val = parseFloat(src.value);
src.value = val.toFixed(5);
} else {
src.value = "0.00000";
}
};
tableEdit.checkFloat6 = function(src) {
var filter = /^-?\d+\.?\d{0,8}$/;
if (filter.test(src.value)) {
var val = parseFloat(src.value);
src.value = val.toFixed(6);
} else {
src.value = "0.000000";
}
};
tableEdit.checkFloat7 = function(src) {
var filter = /^-?\d+\.?\d{0,8}$/;
if (filter.test(src.value)) {
var val = parseFloat(src.value);
src.value = val.toFixed(7);
} else {
src.value = "0.0000000";
}
};
tableEdit.checkFloat8 = function(src) {
var filter = /^-?\d+\.?\d{0,8}$/;
if (filter.test(src.value)) {
var val = parseFloat(src.value);
src.value = val.toFixed(8);
} else {
src.value = "0.00000000";
}
};
return tableEdit;
}