js 获取复选框所有选中的值


<form>
<input type="checkbox" name="game" value=111>111
<input type="checkbox" name="game" value=222>222
<input type="checkbox" name="game" value=333>333
<input type="checkbox" name="game" value=444>444
<input type="checkbox" name="game" value=555>555
<input type="button" value="click" onclick="show()">
</form>

 

获取

<script>
function show(){
items = document.getElementsByName("game");
data = [];
for(x in items){
if(items[x].checked)
data.push(items[x].value);
}
alert(data);

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM