javascript - How to dim an input box after another input box is filling?
问题描述
I have a two input box, which only one of it need to be fill and another is dim.
My problem is, I successful made input box A is filling and input box B was dimmed, but after I clear my input box A, the input box B is still dimmed.
This is my code.
$('#myCodeA').textbox( {
onChange : function(value){
if (value !== 'NULL'){
$('#myCodeB').textbox({'disabled':true});
}else{
$('#myCodeB').textbox({'disabled':false});
}
}
});
$('#myCodeB').textbox( {
onChange : function(value){
if (value !== 'NULL'){
$('#myCodeA').textbox({'disabled':true});
}else{
$('#myCodeA').textbox({'disabled':false});
}
}
});
I expect when the input box A is clear, input box B will undimmed, but it's remain dimmed
Sorry for my english :)
解决方案
使用 Jquery 的 keyup() 事件而不是 onChange()
$("#myCodeA").keyup(function () {
if ($(this).val().length > 0) {
$("#myCodeB").prop("disabled", true);
} else {
$("#myCodeB").prop("disabled", false);
}
});
$("#myCodeB").keyup(function () {
if ($(this).val().length > 0) {
$("#myCodeA").prop("disabled", true);
} else {
$("#myCodeA").prop("disabled", false);
}
});
推荐阅读
- java - 我无法在我的 debian 6 VPS 上安装 Java
- wpf - 如何使用 teststack 获取 WPF TextBlock
- intellij-idea - 我可以在同一台机器上为 CLion 和 IntelliJ IDEA 使用不同的 .ideavimrc 文件吗?
- r - 强制图例中的级别顺序与双向条形图中的顺序相同
- java - org.springframework.batch.item.ItemStreamException:无法在第二个 api 调用上初始化阅读器
- javascript - 视频元素静音在 Chrome 中返回 false,即使属性设置为“静音”
- html - 测量或删除字母上方的空间
- r - 如何在 R 数据框中对多个对象进行分类
- laravel - 在 Laravel 5.4 中注册后向用户发送欢迎电子邮件
- java - java在DTO中将日期类型转换为字符串格式而不需要迭代