如何判断表格中所有输入框是否为空 - JavaScript 代码示例
您可以使用以下代码来判断 td 下的 input 是否全部为空:
var allEmpty = true;
$('td').each(function() {
var input = $(this).find('input');
if (input.length > 0 && input.val() != '') {
allEmpty = false;
return false; // exit the loop
}
});
if (allEmpty) {
console.log('All inputs are empty');
} else {
console.log('Not all inputs are empty');
}
这段代码使用了 jQuery 库来查找每个 td 元素,并检查其下的 input 元素是否为空。如果发现任何一个 input 不为空,则将 allEmpty 标记为 false,并立即退出循环。最后根据 allEmpty 的值来判断是否所有的 input 都为空。
原文地址: https://www.cveoy.top/t/topic/pxqS 著作权归作者所有。请勿转载和采集!