我没有使用此代码获得正确的结果,我不知道为什么。编码应该一次一行地通过表格并收集值和id。如果检索到的值高于/低于当前的高/低,则在另一个表中设置一个字段(有效)。每次通过表单将值添加到表时,都会执行该函数。
我得到的结果集示例:
input total Highest Lowest
Test 1
1 1000 1 1
2 2000 1 2
3 500 1 2
Test 2
1 500 1 1
2 2000 1 2
3 1000 3 2
代码。
function calHiLow() {
var i;
var tableSet = document.getElementsByTagName('table');
var tBody = tableSet[0].tBodies[0];
var noRows = tBody.rows.length;
var row;
var cell;
var iEntryValueCell;
var iEntryValueChildNode;
var iEntryValueNodeValue;
var iEntryValue;
var iEntryNoCell;
var iEntryNoChildNode;
var iEntryNo;
//go through each row and check the total value
for (i = 0; i < noRows; i++) {
//get the first row
row = tBody.rows[i];
//get the row cell of the total column
iEntryValueCell = row.cells[5];
//get the node of the current total node
iEntryValueChildNode = iEntryValueCell.childNodes[0];
//get the value of the current total cell
iEntryValueNodeValue = iEntryValueChildNode.nodeValue;
//remove the $ from the value
iEntryValue = iEntryValueNodeValue.substring(1);
// get the row cell of the Entry No column
iEntryNoCell = row.cells[0];
// get the value of the current Entry No Node
iEntryNoChildNode = iEntryNoCell.childNodes[0];
// get the value of the current Entry No cell
iEntryNo = iEntryNoChildNode.nodeValue;
chkLowest(iEntryValue, iEntryNo);
chkHighest(iEntryValue, iEntryNo);
}
}
function chkLowest(low, EntryNo) {
if (low < LowestValue || LowestValue == null) {
LowestValue = low;
setLowEntry(EntryNo);
}
}
function chkHighest(high, EntryNo) {
if (high > highestValue ||highestValue == null) {
highestValue = high;
setHighEntry(EntryNo);
}
}
全局变量
var highestValue;
var LowestValue;
有什么想法吗?
它正在拉一个字符串我添加了一个parseFloat并且遇到了同样的问题。
当用户在此处添加新值时动态创建表是函数
function addRow() {
var i;
var aLen = newLoan.length;
var content;
var tableSet = document.getElementsByTagName('table');
var table = tableSet[0].tBodies[0];
var newRow = table.insertRow(-1);
for (i = 0; i < aLen ; i++) {
var newCell = newRow.insertCell(-1);
content = document.createTextNode(newEntry[i]);
newRow.appendChild(newCell);
newCell.appendChild(content);
}
var newCell = newRow.insertCell(-1);
newRow.appendChild(newCell);
var btn = document.createElement('button');
newCell.appendChild(btn);
text = document.createTextNode('Remove');
btn.setAttribute('type', 'button');
btn.setAttribute('class', 'pure-button');
btn.setAttribute('value', loanNo);
btn.appendChild(text);
}
数据确实正确地添加到表中,而calHiLow()确实提取了正确的信息。它似乎有问题在chk的