通过替换类名来切换禁用/启用复选框
我有一组 5 个复选框,类别设置为“child”。我希望如果我选择一个复选框,其余的复选框就会被禁用。我尝试过以下代码,但它禁用了所有复选框。
if ( !$(this).is ( ":checked" ) ) {
$(this).removeClass().addClass("hand .parent");
$(".child").attr ( "disabled" , true );
}
然后即使我尝试添加这个
$(this).removeAttr ( "disabled" );
,但它仍然禁用所有控件
帮助请!谢谢
I have a set of 5 checkboxes with class set to "child". I want that if I select one checkbox, rest of them goes disabled. I have tried following code but it disables the all checkboxes.
if ( !$(this).is ( ":checked" ) ) {
$(this).removeClass().addClass("hand .parent");
$(".child").attr ( "disabled" , true );
}
then even i tried adding this
$(this).removeAttr ( "disabled" );
but it still disables the all controls
help plz! Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你想做这样的事情吗?
在这里查看: http://jsfiddle.net/fEA3Y/
如果您由于某种原因确实需要切换类,你可以这样做:
http://jsfiddle.net/fEA3Y/2 /
Are you trying to do something like this?
See it here: http://jsfiddle.net/fEA3Y/
If you really need to toggle classes for some reason, you could do this:
http://jsfiddle.net/fEA3Y/2/
自从您
在
.child
上尝试过之后,由于您没有发布完整的代码,因此很难判断this
的上下文。另外,您是否在某个地方没有设置
readonly
属性?Did you do
Since you tried it on
.child
, it's kind of hard to tell the context ofthis
since you're not posting the full code.Also, are you there there isn't a
readonly
attribute being set somewhere?