[英]The submit button works only once
I developed a function that keeps the submit disabled until filling all the fields.我开发了一个功能,可以在填写所有字段之前禁用提交。 The function works, but when I create two more users the submit button enables before filling the fields;
该功能有效,但是当我再创建两个用户时,提交按钮会在填写字段之前启用; my function works only once.
我的功能只工作一次。
The button is working and the data is saved, but the submit button is enabled before filling the fields.该按钮正在工作并保存数据,但在填写字段之前启用了提交按钮。
$(document).ready(function () {
$('#myForm input').keyup(function () {
var empty = false;
$('#myForm input').each(function () {
if ($(this).val().length == 0) {
empty = true;
}
});
if (empty) {
$('#btnsave').attr('disabled', 'disabled');
} else {
$('#btnsave').attr('disabled', false);
}
return empty;
});
});
i think you create new inputs dynamically, then try this:我认为你动态创建新的输入,然后试试这个:
$('#myForm').on('keyup', 'input', function () {
var empty = false;
$('#myForm input').each(function () {
if ($(this).val().length == 0) {
empty = true;
}
});
if (empty) {
$('#btnsave').attr('disabled', 'disabled');
} else {
$('#btnsave').attr('disabled', false);
}
return empty;
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.