选择复选框,我有以下的HTML:jQuery的:基于名称和值
<form id="test">
<input type="radio" value="A" name="C1"/>
<a href="javascript:selectCheckbox('C1', 'A');"> OPTION-A </a>
<input type="radio" value="B" name="C1"/>
<a href="javascript:selectCheckbox('C1', 'B');"> OPTION-B </a>
<input type="radio" value="C" name="C1"/>
<a href="javascript:selectCheckbox('C1', 'C');"> OPTION-C </a>
// several other: C2, C3, ..
</form>
而且我想实现selectCheckbox(chkbox, value)
,这应该:
- 搜索所有无线电与
name = chkbox
和设置attr('checked') = false
- 搜索收音机有
name = chkbox AND val() = value
和设置attr('checked') = true
我想不通,正确的选择是什么,我想没有任何运气如下:
var name = "#" + chkbox + " :checked";
$(name).each(.. // doesn't work
$('#'+chkbox).each(.. // if finds only the first occurence
// of i.e. C1, although I would expect 3
$("input[@name='"+chkbox+"']").each(function() { ..
// leaves me with the following error:
// Warning: Expected attribute name or namespace but found '@name'
请让我知道我做错了。非常感谢!
的代码你不应该有相同的ID(“C1”)的多个元素 – Zed 2009-09-19 17:13:35
你说得对,我删除了ID现在。谢谢! – MrG 2009-09-19 17:15:41
“注意:在jQuery 1.3 [@attr]样式选择器被删除(他们以前在jQuery 1.2中被弃用)。“ – Zed 2009-09-19 17:17:19