这与其他选择器

时间:2012-08-10 08:43:15

标签: jquery html this

我正在尝试在每个div中显示所选复选框的数量,但不知道如何选择span

$("input[@type=checkbox]:checked",this).length工作正常,我已将其设置为警告且数字正确,但我不知道如何为每个div选择#skills div h3 span

HTML

<td id="skills" colspan="2">
  <div id="skills_0">
    <h3>IT<span></span></h3>
    <input type="checkbox" name=".." id=".." val=".." /> <label for="..">..</label>
    ...<!-- more inputs -->
  </div>
  ...<!-- more divs -->
</td>

jQuery的:

$(document).ready( function () {
    $('#skills div').each( function () {
        $("h3 span",this).html($("input[@type=checkbox]:checked",this).length);
    });
});

1 个答案:

答案 0 :(得分:1)

试试这个:

/* $(this).find('span').html($("input[@type=checkbox]:checked",this).length); */

新的更新代码:

$(this).find("h3 span").html($("input[@type=checkbox]:checked",this).length);

演示:

http://jsfiddle.net/ongisnade/VQutV/3/

相关问题