javascript - 在 Bootstrap 中禁用输入字段

标签 javascript html twitter-bootstrap

我在 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/

相关文章:

html - 如何定位grails g :render中的单个元素

html - 使用 CSS 类继承引导网格系统

javascript - 在另一个模态之上打开一个 bootbox 模态不会使后面的模态变暗

jquery - 根据页面不同地设计 WordPress Contact Form 7

javascript - 我试图在完成后仅显示表格,然后显示表格 2,表格 2 不会显示?

javascript - 在 HTML 表格中添加空白行

javascript - Chrome 中的 AngularJS CORS 问题 - 请求的资源上不存在 'Access-Control-Allow-Origin' header

javascript - ( | ) 和 ( || ) 有什么区别?

html - 仅使用CSS将图片制作成圆形 View

javascript - 如何通过单元测试检查字符串是否恰好出现 1 次?