我试图在取消选中复选框时禁用日期字段,反之亦然。
http://jsfiddle.net/MyNameIsSakthi/ZKw9x/2/
此外,这在不同的浏览器中的工作方式也不同!
$('#certExpiry').click(function(){
if($('#certExpiry').is(':checked')){
alert('checked');
$('#expiryDate').removeProp('disabled');
}
else
alert('uncheck');
$('#expiryDate').prop('disabled',true);
});
最佳答案
你可能想要这样的东西......
$('#certExpiry').click(function () {
$('#expiryDate').prop('disabled', !this.checked);
});
jsFiddle .
另外,不要使用 removeProp()
像那样。该文档清楚地说明了这一点...
Note: Do not use this method to remove native properties such as
checked
,disabled
, orselected
. This will remove the property completely and, once removed, cannot be added again to element. Use.prop()
to set these properties tofalse
instead.
关于javascript - 禁用/启用输入 :date on checkbox click doen't work properly?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16433544/