Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/442.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 查找表的最高值和最低值_Javascript - Fatal编程技术网

Javascript 查找表的最高值和最低值

Javascript 查找表的最高值和最低值,javascript,Javascript,我没有得到正确的结果与此代码,我不知道为什么。编码的数据应该一次遍历一行表,并收集值和id。如果检索到的值高于/低于当前的高/低,则在另一个表中设置一个字段(有效)。每次通过表单向表中添加值时,都会执行该函数 我得到的结果集示例: input total Highest Lowest Test 1 1 1000 1 1 2 2000 1 2 3 500

我没有得到正确的结果与此代码,我不知道为什么。编码的数据应该一次遍历一行表,并收集值和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); 
}
}
有什么想法吗

它是拉一个字符串,我添加了一个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);
函数addRow(){
var i;
var aLen=newLoan.length;
var含量;
var tableSet=document.getElementsByTagName('table');
var table=tableSet[0].tBodies[0];
var newRow=table.insertRow(-1);
对于(i=0;i
}


数据确实正确地添加到表中,而calHiLow()确实提取了正确的信息。似乎有问题的地方是chk的

有点难以遵循,但您得到的值的类型是什么?我不是100%确定,但是从HTML中提取数据应该会得到字符串,这显然不像数字那么容易比较。您有正在使用的原始HTML表的示例吗?
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);