我有以下 HTML:
<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'
请让我知道我做错了什么。非常感谢!
尝试这个:
$('input:radio[name="' + chkboxName + '"][value="' + value + '"]')
.attr('checked', 'checked');
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)