点击按钮查看元素的选中状态

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="体育" />体育

 

posted @ 2017-04-18 11:35  念念念不忘  阅读(306)  评论(0)    收藏  举报