js获取所有被选中的checkbox值

    <label for=""><span>1</span><input type="checkbox" value="1"></label>
    <label for=""><span>2</span><input type="checkbox" value="2"></label>
    <label for=""><span>3</span><input type="checkbox" value="3"></label>
    <label for=""><span>4</span><input type="checkbox" value="4"></label>
    <button>提交</button>
    <script>
        var oBtn = document.getElementsByTagName("button")[0];
        oBtn.onclick = function(){
            var oTxt = document.getElementsByTagName("input");
            for (var i = 0; i < oTxt.length; i++) {
                if(oTxt[i].checked){
                    alert(oTxt[i].value);
                }
            }
        }
    </script>

没有更多推荐了,返回首页