【发布时间】:2012-07-06 15:46:10
【问题描述】:
我正在编写一个基本脚本,但我似乎无法理解为什么它不起作用。基本上,如果选中一个复选框,脚本会锁定所有复选框,然后如果用户决定取消选中复选框,则将其解锁。
这里是代码
//Script for questions where you check one option or the other (locks other options out)
$('.optionBox input').click(function(){
var optionBoxElement$ = $(this).closest('.optionBox');
//If no option is checked, the make all the options available to be selected
//Otherwise, one option must be checked so lock out all other options
if(optionBoxElement.find('input:not(:checked)').length == optionBoxElement.find(':input').length)
optionBoxElement.find(':input').prop('disabled',false);
else
optionBoxElement.find('input:not(:checked)').prop('disabled',true);
optionBoxElement.find('input:checked').prop('disabled',false); //makes sure that the checkbox that was checked is not disabled so the user can uncheck and change his answer
});
【问题讨论】:
-
第一个问题:为什么不使用单选按钮?
-
不适合我的应用程序。我只想要一个针对这种情况的通用脚本。
-
尝试添加HTML,看看是否有错误
-
太糟糕了,它给了我
$inputs.prop is not a function我切换到js(链接)[stackoverflow.com/questions/6060681/…
标签: javascript jquery html