开发者

using Change on an Input and then modifying the input's ATTR?

开发者 https://www.devze.com 2023-03-16 07:23 出处:网络
Given: html <input checked=\"checked\" class=\"l开发者_开发问答ist_completed_checkbox\" id=\"list_item_completed\" name=\"list_item[completed]\" type=\"checkbox\" value=\"1\">

Given:

html

<input checked="checked" class="l开发者_开发问答ist_completed_checkbox" id="list_item_completed" name="list_item[completed]" type="checkbox" value="1">

jQuery:

$('.list_completed_checkbox').change(function() {
    $(this).attr('disabled', 'disabled');
});

When you check or uncheck the checkbox, Why isn't the disabled attr being applied to the input?

Thanks


Your code works for me:

http://jsfiddle.net/jasongennaro/qYe96/

Perhaps something else is interfering?


i don't think an input has a change event. you might want to do a focus or blur depending on what you need.

$('.list_completed_checkbox').blur(function() {
    $(this).attr('disabled', 'disabled');
});


try this:

    $('.list_completed_checkbox').change(function() {
        $(this).attr('disabled', true);
    });
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号