900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > react 全选反选_js中怎么将createElement出来的复选框实现全选 全不选 反选效果?...

react 全选反选_js中怎么将createElement出来的复选框实现全选 全不选 反选效果?...

时间:2023-07-25 05:48:31

相关推荐

react 全选反选_js中怎么将createElement出来的复选框实现全选 全不选 反选效果?...

const checkBoxs = ["篮球","足球","羽毛球","乒乓球"];

const creactCheckBox = text => {

let checkBox = document.createElement("input");

checkBox.setAttribute("type","checkBox");

document.body.insertAdjacentElement("beforeend", checkBox);

document.body.insertAdjacentText("beforeend", text);

};

checkBoxs.forEach((item,index) => creactCheckBox(item));

const selector = dom => document.querySelectorAll(dom);

const [checkAllBtn,checkNotBtn,checkRevBtn] = [selector("#checkAllBtn")[0],selector("#checkNotBtn")[0],selector("#checkRevBtn")[0]];

const actions = {

checkAll(){

selector("input[type='checkBox']").forEach(function (option,index) {

option.checked = true

})

},

checkNot(){

selector("input[type='checkBox']").forEach(function (option,index) {

option.checked = false

})

},

checkRev(){

selector("input[type='checkBox']").forEach(function (option,index) {

option.checked ? option.checked = false : option.checked = true

})

}

};

checkAllBtn.addEventListener("click",function(){actions.checkAll()});

checkNotBtn.addEventListener("click",function(){actions.checkNot()});

checkRevBtn.addEventListener("click",function(){actions.checkRev()})

花了三分钟帮你写,包含ES6箭头函数

const

forEach

解构赋值

querySelectorAll

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。