原生JS——checkbox操作技巧【转】

2.根据type="checkbox"选中所有checkbox

const checkList = document.querySelectorAll('input[type="checkbox"]');

3.修改checkbox选中状态

// 选中
document.querySelector('input[type="checkbox"]').checked = true;
// 取消选中
document.querySelector('input[type="checkbox"]').checked = false;

4.获取checkbox的value

const curValue = document.querySelector('input[type="checkbox"]').value;

文章来自:https://www.jianshu.com/p/ea583ec4fb82

posted @ 2020-06-13 14:52  小猿笔记  阅读(1493)  评论(0编辑  收藏  举报