如何捕获“UL”标签内的复选框值

时间:2015-02-22 19:07:20

标签: javascript jquery html

<ul class = "classUL" id = "idUl1">
    <li>
        <label class = "classLabel">
            <input type = "checkbox" class = "classCheck" id = "idchk1"> Test Test Test
            </label>
    </li>
        <li>
        <label class = "classLabel">
            <input type = "checkbox" class = "classCheck" id = "idchk2" checked= "true" > Test Test Test
        </label>
    </li>
</ul>

<ul class = "classUL" id = "idUl2">
    <li>
        <label class = "classLabel">
            <input type = "checkbox" class = "classCheck" id = "idchk1"> Test Test Test
        </label>
    </li>
    <li>
        <label class = "classLabel">
            <input type = "checkbox" class = "classCheck" id = "idchk2" checked= "true" > Test Test Test
        </label>
    </li>
</ul>

我有几个列表......我想得到第二个复选框的值,就像我在JS或jQuery中那样?当我在列表中以获取复选框的值(没有检查的id标签)?

2 个答案:

答案 0 :(得分:0)

在Javascript中: var v=document.getElementById("idchk2").value;

答案 1 :(得分:0)

请在HTML标记中使用唯一ID

$(document).ready(function(){ 
   $("ul.classUL").each(function(){

      $(this).find(".classCheck").each(function(){
        console.log($(this).val());
      });

    });
});

将为您提供所有复选框的价值。