[英]If Checkbox is checked, remove attribute?
<div class="span1">
<input type="checkbox" value="l4" id="l4" field="" defaultValue="" appEditor="true"/>
</div>
<div class="span7">
<input type="text" class="m-wrap span10" id="fld_l4" defaultValue="" editType="intEdit" appEditor="true" disabled />
</div>
What I want to do is, If checkbox is checked, remove disabled in the fld_l4. 我想做的是,如果选中了此复选框,请在fld_l4中删除禁用的功能。
How to do this with using Prototype.js or jQuery? 如何使用Prototype.js或jQuery做到这一点?
EDIT: I'm using prototype with jQuery i'm getting an error: Uncaught InvalidStateError: An attempt was made to use an object that is not, or is no longer, usable.
编辑:我正在使用jQuery的原型,我得到一个错误:
Uncaught InvalidStateError: An attempt was made to use an object that is not, or is no longer, usable.
By the way i replaced $ with jQuery for conflicts 顺便说一下,我用jQuery替换$来解决冲突
EDIT2 : Solved. EDIT2:已解决。
this.l4 = editor.instance;
editor.observe(iconstants.KEY_CHANGE,this.levelCheckboxChanged.bindAsEventListener(this))
Inside levelCheckboxChanged: 内部levelCheckboxChanged:
levelCheckboxChanged: function(e) {
if($("l4").checked == false) {
$("fld_l4").disabled = true;
} else {
$("fld_l4").disabled = false;
}
},
This way should work: 这种方法应该起作用:
$("#l4").on("change", function () {
$("#fld_l4").prop("disabled", !$(this).is(":checked"));
});
jsFiddle: http://jsfiddle.net/J5Nt2/1/ jsFiddle: http : //jsfiddle.net/J5Nt2/1/
Try this, 尝试这个,
if( $("#l4:checked").length ) {
$("#fld_l4").removeAttr("disabled");
}
Here is the way to do this with PrototypeJS 这是使用PrototypeJS做到这一点的方法
inside of your DOM loaded event 在您的DOM加载事件中
document.observe('dom:loaded',function(){
$('l4').observe('click',function(){
$('fld_l4').writeAttribute('disabled',this.checked);
});
});
Plus you might want to change the id of '14' browsers do not like you starting id's with numbers - they let you do it but it is not part of the HTML spec
另外,您可能想要更改“ 14”浏览器的ID,这与您不希望您使用数字开头的ID一样-它们允许您这样做,但它不是HTML规范的一部分
Try this: 尝试这个:
if( $("#l4").is(":checked") ) {
$('#fld_l4').removeAttr('disabled');
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.