首页 > 解决方案 > 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 :)

标签: javascriptjqueryonchangeonselect

解决方案


使用 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);
            }

        });

推荐阅读