免费文案素材网站,陕西网站建设设计公司,什么好的网站学做食品,鄂州建设工程造价信息网需求#xff1a;用户第一次点击某些元素#xff0c;改变元素的某些样式#xff0c;比如背景颜色#xff0c;字体颜色。用户第二次点击某些元素#xff0c;恢复之前的样式。.....思路#xff1a;准备一定量的div盒子#xff0c;并取相同的类名div classbox用户第一次点击某些元素改变元素的某些样式比如背景颜色字体颜色。用户第二次点击某些元素恢复之前的样式。.....思路准备一定量的div盒子并取相同的类名div classbox /divdiv classbox/divdiv classbox/divdiv classbox/divdiv classbox/divdiv classbox/divdiv classbox/div通过js获取所有元素并给定指令。使得点击任意一个盒子都可随意改变原有样式而不影响其他盒子判断如果当前点击的盒子背景被改变则再点击当前盒子背景恢复。效果代码实现!DOCTYPE htmlhtml head meta charsetutf-8 title/title /head style .box { width: 50px; height: 50px; background-color: aqua; margin: 5px; } /style body div classbox/div div classbox/div div classbox/div div classbox/div div classbox/div div classbox/div div classbox/div script let box document.querySelectorAll(.box); for (let i 0; i box.length; i) { box[i].onclick function() { if (box[i].style.background || box[i].style.background undefined) { box[i].style.background red } else { if (box[i].style.background red) { box[i].style.background aqua } else if (box[i].style.background aqua) { box[i].style.background red } } } } /script /body/html