点击按钮查看元素的选中状态
var oForm = document.getElementById('form1'); oBtn.onclick = function() { for (var i=0; i<oForm.aihao.length; i++) { if (oForm.aihao[i].checked) { alert(oForm.aihao[i].value + ' 选中了'); } else { alert(oForm.aihao[i].value + ' 没选中'); } } }
<input type="checkbox" name="aihao" value="电影" />电影 <input type="checkbox" name="aihao" value="音乐" />音乐 <input type="checkbox" name="aihao" value="体育" />体育