启用不起作用jQuery

时间:2015-05-30 20:16:55

标签: jquery disabled-input

我尝试根据其他文本框的输入禁用/启用文本框。 当role文本框的输入为_teacher_时,subject文本框为enable。否则,disabled

问题是当输入为teacher

时,它不会启用它
function check(event) {
    if ($('#role').val().toLowerCase() == "teacher")
            $("#subject").removeAttr("disabled"); 
    else
        $("#subject").attr("disabled", "disabled"); 
}

view.tpl

<input type="text" class="input-block-level" id="role" onkeypress="check(event)" placeholder="Teacher/HR" name="role"/>
<br/>
<input type="text" class="input-block-level" id="subject" placeholder="Subject(only if Teacher) " name="subject"/>
<br/>

1 个答案:

答案 0 :(得分:0)

尝试$("#subject").prop("disabled", false);启用,$("#subject").prop("disabled", true);禁用元素