ho il seguente codice HTML:jQuery: selezionare casella di controllo in base al nome e il valore
<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>
E sto cercando di attuare selectCheckbox(chkbox, value)
, che dovrebbe:
- ricerca di tutte le radio di con
name = chkbox
e setattr('checked') = false
- di ricerca per la radio avere
name = chkbox AND val() = value
e impostareattr('checked') = true
io non riesco a capire, ciò che il selettore di destra è, ho provato quanto segue senza alcuna fortuna:
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'
prega fatemi sapere cosa sto facendo male. Molte molte grazie!
non dovreste avere più elementi con lo stesso ID ("C1") – Zed
Hai ragione, ho tolto l'ID è ora. Grazie! – MrG
"Nota: In jQuery 1.3 [@attr] i selettori di stile sono stati rimossi (erano precedentemente deprecati in jQuery 1.2).Basta rimuovere il simbolo '@' dai selettori per farli funzionare di nuovo. " – Zed