gpt4 book ai didi

javascript - 如何发现表格中所有的输入文本框都是空的?

转载 作者:行者123 更新时间:2023-11-30 08:24:34 24 4
gpt4 key购买 nike

我有一个 html 表,其中包含类似

的数据
<table>
<tr>
<td>abc</td>
<td>781</td>
<td><input id="barcodedb0" class="hide" type="text" /><input id="barcode0" class="hide" type="text" /></td>
</tr>
<tr>
<td>abc</td>
<td>781</td>
<td><input id="barcodedb0" class="hide" type="text" /><input id="barcode0" class="hide" type="text" /></td>
</tr>
</table>

在 JQuery 中

$('#library_info_tbl tbody').on("keyup", "tr td input:nth-child(2)", function() {
if(all the textboxes are empty)
// do something
});

我想知道如何检查表格中的所有文本框是否为空。

请注意,具有“隐藏”类的文本框是隐藏的,用于其他目的。

请帮忙!!!

最佳答案

你可以用这个此代码仅适用于第二个输入。

$('#library_info_tbl tbody').on("keyup", "tr td input:nth-child(2)", function() {
var oneEmpty = false;
$("#library_info_tbl tbody tr td input:nth-child(2)").filter(function () {
return $.trim($(this).val()) == '';
});
if(oneEmpty)
// do something
});

此代码仅适用于所有输入。

$('#library_info_tbl tbody').on("keyup", "tr td input:nth-child(2)", function() {

if($("#library_info_tbl tbody input:empty").length == $("#library_info_tbl tbody input").length)
{
// do something
}
});

// Instead of $("#library_info_tbl tbody input:empty") you can also use $("input.hide:empty")

关于javascript - 如何发现表格中所有的输入文本框都是空的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47768540/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com