如何在jquery中启用和禁用文本框

jas*_*sim 7 html javascript jquery

我已经编写了一个html和脚本的示例代码,如下所示:当我执行此代码时,我将获得该警报,但是当我通过按Tab键更改cca时,其他警报则显示警报.如何使用该文本框并启用和禁用它的其他文本字段.

HTML:

<div id="cca" class="leaf">
     <label class="control input text" title="">
        <span class="wrap">cca</span>
        <input class="" type="text" value="[Null]">
        <span class="warning"></span>
     </label>
</div>
Run Code Online (Sandbox Code Playgroud)

JS:

jQuery(document).ready(function () {        
    alert("hello");        
    jQuery("#cca label.control input").on('change', function (event) {
        alert('I am pretty sure the text box changed');
        event.preventDefault();
    });
});
Run Code Online (Sandbox Code Playgroud)

Pur*_*gon 2

我不太确定你想做什么,但我可以帮助让警报正常工作。您基本上没有正确使用 jQuery“on”功能。

$('#thisNeedsToBeContainer').on('focusout', '#elemToBindEventTo', function (event)....

以下之一将满足您的需要:

当文本框离开时这将触发

$(document).ready(function () {      

    alert("hello");        
    $("#cca").on('focusout', 'label.control input', function (event) {
        alert('I am pretty sure the text box changed');
        event.preventDefault();
    });
});
Run Code Online (Sandbox Code Playgroud)

这,将火上浇油change

$(document).ready(function () {       
    alert("hello");        
    $("#cca").on('change', 'label.control input', function (event) {
        alert('I am pretty sure the text box changed');
        event.preventDefault();
    });
});
Run Code Online (Sandbox Code Playgroud)

keyup这将在打字时触发

$(document).ready(function () {  
    alert("hello");        
    $("#cca").on('onkeyup', 'label.control input', function (event) {
        alert('I am pretty sure the text box changed');
        event.preventDefault();
    });
});
Run Code Online (Sandbox Code Playgroud)

请参阅JsFiddle上的演示

您还应该关闭您的输入:

<input class="" type="text" value="[Null]"/>
Run Code Online (Sandbox Code Playgroud)