现在只能获取第一个的值,其他的都获取不了<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>demo</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#selectTest").click(function(){
   alert($(this).val());

})
})
</script>
</head>
<body>
    <input name="selectTest" id="selectTest" type="checkbox" value="12" /><br />
    <input name="selectTest" id="selectTest" type="checkbox" value="11" /><br />
    <input name="selectTest" id="selectTest" type="checkbox" value="10" />
</body>
</html>

解决方案 »

  1.   

    页面中id不能重复,去掉id直接用name($("div[name='selectTest']"))或者用别的属性都可以
      

  2.   

    $(function(){
        $("select").each(function(){
         alert($(this).val());
       })})
      

  3.   

    错了,应该是这个
     $(function(){ 
        $("input").each(function(){ 
        alert($(this).val()); 
      }) })
      

  4.   


        $(function(){
            $(":checkbox[name='selectTest']").click(function(){
                       alert($(this).val());
                    
            });
        })