0

这段代码我没有得到正确的结果,我不知道为什么。编码应一次通过表一行并收集值和 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 上

4

0 回答 0