checkbox,选中

<html>
<head>  
<script type="text/javascript">

function testCheckBox(){

var vehicle = document.getElementById('vehicle');
 for (var i=0; i < vehicle.length; i++){                     

    alert(vehicle[i].checked); 
    if (trucks[i].checked){

         alert('at least one was selected');
     return true;
     }
    }

alert('Please select one');
return false;
    }
</script>

</head>
<body>

<form>
<input type="checkbox" name="vehicle" value="Bike" /> I have a bike<br />
<input type="checkbox" name="vehicle" value="Car" /> I have a car
<br />
<input type="button" name="test" value="test" onclick="testCheckBox();" />

</body>
</html>
posted @ 2015-03-11 11:18  庄姜琴瑟  阅读(164)  评论(0编辑  收藏  举报