html的全选反选

一、实验题目

html实现选择框的全选和反选

二、实验代码

复制代码
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>全选和反选</title>
	</head>
	<body>
		<ul>兴趣爱好</ul>
		<input id="all" type="checkbox">全选
		<ul>
			<input type="checkbox" class="all_check">听音乐
			<input type="checkbox" class="all_check">玩游戏
			<input type="checkbox" class="all_check">做运动
			<input type="checkbox" class="all_check">吃美食
			<input type="checkbox" class="all_check">看电影
		</ul>
		
		<script>
			let all = document.getElementById("all")
			let input_arr = document.querySelectorAll("ul>input")
			
			all.onclick = function(){
				if(all.checked == true){
					for(input of input_arr){
						input.checked = true
					}
				}else{
					for(input of input_arr){
						input.checked = false
					}
				}
			}
		</script>
	</body>
</html>

三、效果演示

相关推荐
椒哥8 分钟前
一天被问几十次"允许",我统计了 517 次,然后写了个插件
前端·javascript·github
风骏时光牛马10 分钟前
生成一个AI稳定性治理及疑难问题分析标题,只需要一个标题,不需要其他的任何文本。
前端
莫西干式秃头25 分钟前
用 AI + threejs 写了个浏览器里的 3D 动作游戏《武来》:砍怪、放技能、开 SU7
前端·人工智能·three.js
kyriewen39 分钟前
我测了 6 种防请求竞态的写法:只有 1 种真能打
前端·javascript·程序员
孟健42 分钟前
用 WorkBuddy 做个人名片网页,挂上开源设计技能后效果完全不同了
前端·人工智能·ai编程
IT_陈寒1 小时前
SpringBoot自动配置的坑,这次终于爬出来了
前端·人工智能·后端
LuHang2 小时前
从天地图切换到高德地图:一次真实的底图迁移实战
前端·vue.js·cesium
用户360055579002 小时前
Kestrel_VLLM - 27 · 寄存器常驻与融合发射:两次「少发一次」
前端
前端小万2 小时前
用"道法术器"重构你和 AI 的协作方式
前端·人工智能·程序员
鶴哥只手遮天2 小时前
Angular 22 源码级深度解析-第 06 章 模板指令全解:`ɵɵelementStart`、`ɵɵproperty`、`ɵɵadvance` 与绑定指令
前端·开源·angular.js