<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>如何获取Checkbox当前行的ID</title>
<script type="text/javascript" src="jquery.js"> </script>  <!-- 需要引用jquery包 -->
<script type="text/javascript">
$(document).ready(function()
{  
$(".dataTable tr").dblclick(function()

alert( $("____").attr("id") ); //帮忙填个空,用于双击行,获取checkbox的ID。
})
});
</script>
</head>
<body>
    <table class="dataTable" border="1" width="100%">
<tr>
<td><input id="Checkbox1" type="checkbox" class="1" /></td> <!-- checkbox的 ID 是活的 -->
<td>&nbsp;</td>
</tr>
<tr>
<td><input id="Checkbox2" type="checkbox"/></td>
<td>&nbsp;</td>
</tr>
<tr>
<td><input id="Checkbox3" type="checkbox"/></td>
<td>&nbsp;</td>
</tr>
    </table> 
</body>
</html>
控件“checkbox”的数量和Id是动态的,我目的是想双击行的时候,获取行首的“checkbox”对象,以便决定是否打勾。

解决方案 »

  1.   


    $(".dataTable tr").dblclick(function() { 
        $(this).find(":checkbox").each(function(){this.checked=true;});
    })
      

  2.   

    alert( $(this).find("input[type='checkbox']").attr("id") ); //帮忙填个空,用于双击行,获取checkbox的ID。
      

  3.   

    alert( $("____").attr("id") ); ==>alert( $(this).find("input[type='checkbox']").attr("id") ); 
      

  4.   


    $(document).ready(function()
        {         
            $(".dataTable tr").dblclick(function()
            { 
                var ckList = $("input[type='checkbox'");
                if(ckList.length>0)
                   alert(ckList[0].id );
            })
        });
      

  5.   


    var obj = $(this).find("input[type='checkbox']").get(0); 
    obj.checked=obj.checked?false:true;