只要任何表格单元格包含零,我就需要停止执行 JavaScript 函数。我尽力了,但似乎没有任何效果。我不明白为什么它不起作用。
function ZeroCheck(IDTable) {
var myData = [];
$('#' + IDTable).find("tr:gt(0)").each(function(i, row) {
var oRow = [];
$(row).find("td").each(function(j, cell) {
if ($(cell).text() == '0') {
alert('Please correct input. There should not be a 0 in any cell');
return false;
}
oRow.push(parseFloat($(cell).text()));
});
myData.push(oRow);
});
};
最佳答案
请试试这个:
function ZeroCheck(IDTable) {
let isZeroDetectted = false;
let myData = [];
$('#' + IDTable).find("tr:gt(0)").each(function(i, row) {
let oRow = [];
$(row).find("td").each(function(j, cell) {
if ($(cell).text() == '0') {
alert('Please correct input. There should not be a 0 in any cell');
isZeroDetectted = true;
return false;
}
oRow.push(parseFloat($(cell).text()));
});
if(isZeroDetectted){
return false;
}
myData.push(oRow);
});};
关于Javascript 在单元格仅包含 0 后停止执行;,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48260039/