2011-06-30 66 views
0

考虑:在输入上使用更改,然后修改输入的ATTR?

HTML

<input checked="checked" class="list_completed_checkbox" id="list_item_completed" name="list_item[completed]" type="checkbox" value="1"> 

的jQuery:

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

当您选中或取消选中该复选框,为什么不是禁用ATTR被应用于输入?

谢谢

+0

工作正常,我(在Chrome,IE6-9和Firefox 4):http://jsfiddle.net/Z9uyD/ –

回答

1

我不认为输入有变化事件。你可能想根据你需要做一个焦点或模糊。

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

投入肯定是有变化的事件......你可以看到OPs示例在这里工作:http://jsfiddle.net/Z9uyD/ –

+0

更改甚至触发,attr没有被应用,虽然 – TheExit

+0

@詹姆斯 - 你是绝对正确 –

1

试试这个:

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

@TheExit我希望这将是所有人 – thecodeparadox