<分区>
编辑问题以包含 desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem .这将有助于其他人回答问题。
关闭 6 年前。
<分区>
编辑问题以包含 desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem .这将有助于其他人回答问题。
关闭 6 年前。
我正在尝试实现代码,如果输入的任何输入值为零,则禁用按钮,否则启用。当输入的输入值为零时它工作正常,但在我输入除零以外的值后它仍然禁用不启用我正在使用计数器并且我总共有将近 40 个文本字段要检查所以我在每个语句中使用输入类型。
以下是我实现的 fiddle 。
最佳答案
你每次都需要初始化计数值
,因为你要检查这个值是不是0值的声明。把它的设置值放在.change()
功能
$(document).ready(function() {
$('input').change(function() {
var count = 0;
$("input").each(function() {
if($(this).val() == "0")
{
count = 1;
}
});
if(count == 0)
{
$("#submitBtn").removeAttr("disabled","disabled");
}
else
{
$("#submitBtn").attr("disabled","disabled");
}
});
});
关于javascript - 如果任何输入字段值输入零,则禁用,否则启用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43134093/
相关文章:
javascript - Dojo DataGrid (DGrid) 添加复选框列
javascript - 如何使用 JS 编辑 CSS 变量?
javascript - 不将函数声明为另一个自定义函数的原型(prototype)的用例?
javascript - 循环遍历多边形特征谷歌地图API v 3
javascript - 在动态创建的输入字段上启用 jQuery 自动完成
javascript - IE 11 “An error has occurred in the script on this page”在行尾