不知道如何做到这一点......但这就是我想要做的:
我有一系列单选框
<div id="xrowcont_0">
<input type="radio" name="13_641" value="a" id="13_641_form_a" ><label for="13_641_form_a"><span></span></label>
<input type="radio" name="13_641" value="b" id="13_641_form_b" checked="checked"><label for="13_641_form_b"><span></span></label>
<div id="xmod_mach_list_0" style="display:none;">BOO1</div>
</div>
<div id="xrowcont_1">
<input type="radio" name="13_642" value="a" id="13_642_form_a"><label for="13_642_form_a"><span></span></label>
<input type="radio" name="13_642" value="b" id="13_642_form_b"><label for="13_642_form_b"><span></span></label>
<div id="xmod_mach_list_1" style="display:none;">BOO2</div>
</div>
... ++++
这个想法是,当您在 中选择单选框“B”时<div id="xrowcont_0">
,它会<div id="xmod_mach_list_1"
在每一行旁边取消隐藏。
这是js:
假设我们有 13 行...
for (var i=0;i<13;i++) {
var a1 = "'#xrowcont_" + [i] + " input[type=radio]'";
var a2 = "'#xrowcont_" + [i] + " input:checked'";
console.log(a1);
console.log(a2); // these show up just fine.
$(a1).on( "click", function() { // but here it breaks.
var state = $(a2).val();
if (state == "b") {
$('#xmod_mach_list_' + [i] ).css('opacity',0).show().animate({ opacity: 1 }, 300);
console.log("Show Button");
} else {
$('#xmod_mach_list_' + [i] ).animate({ opacity: 0} , 200);
setTimeout(function () {$('#xmod_mach_list_' + [i] ).hide(); }, 200);
console.log("Hide Button");
};
});
}
它给了我Uncaught Error: Syntax error, unrecognized expression: '#xrowcont_0 input[type=radio]'
,尽管那是我想要在... $(a1).on( "click", function() {...
等部分中填充的内容。
我怎样才能解决这个问题?