我在 Bootstrap 中有 3 个输入字段,如果其中一个输入字段已填充,我想禁用其他两个。
假设我有 A、B、C 输入框。
如果 A 被填充,则 B 和 C 将变为禁用
或只读
,反之亦然。
此外,如果我从 A 中删除值,则 B 和 C 将再次启用。由于 B 和 C 也没有填写。
最佳答案
你只需做一个 jQuery 函数
// #your_filled_input is for the id of the input
$("#your_filled_input").keyup(function() {
if ($("#your_filled_input").val().length >= 0) {
$("#your_first_other_field" ).attr('disabled', 'disabled');
$("#your_second_other_field").attr('disabled', 'disabled');
}
});
关于javascript - 在 Bootstrap 中禁用输入字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29253431/