我有以下复选框:
<ul class="checkbox_list">
<li><input name="mensajes[receptores_list][]" type="checkbox" value="5" id="mensajes_receptores_list_5" /> <label for="mensajes_receptores_list_5">Carlos (Admin)</label></li>
<li><input name="mensajes[receptores_list][]" type="checkbox" value="1" id="mensajes_receptores_list_1" /> <label for="mensajes_receptores_list_1">Jorge (Admin)</label></li>
<li><input name="mensajes[receptores_list][]" type="checkbox" value="3" id="mensajes_receptores_list_3" /> <label for="mensajes_receptores_list_3">Marisa (Admin)</label></li>
<li><input name="mensajes[receptores_list][]" type="checkbox" value="6" id="mensajes_receptores_list_6" /> <label for="mensajes_receptores_list_6">Christian (Apuntes)</label></li>
<li><input name="mensajes[receptores_list][]" type="checkbox" value="4" id="mensajes_receptores_list_4" /> <label for="mensajes_receptores_list_4">Julieta (Contable)</label></li>
<li><input name="mensajes[receptores_list][]" type="checkbox" value="2" id="mensajes_receptores_list_2" /> <label for="mensajes_receptores_list_2">Vicky (Contable)</label></li>
</ul>
使用javascript,我如何访问每个项目的文本。例如,对于id =“ mensajes_receptores_list_5”的元素,我要获取文本“ Carlos(Admin)”
通过Jquery
function getLabel(id)
{
return $("#"+id).next("label").html();
}
//id of checkbox ,you want to get label of
var label=getLabel('mensajes_receptores_list_1');
alert(label);
Jsfiddle http://jsfiddle.net/pcQgE/1/
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句