1. 实例演示classList对象 2. 使用blur事件进行表单非空验证
16lz
2022-04-10
classList对象
示例代码:
<style>
.box {
background-color: yellow;
color: red;
}
.active {
border: 1px solid #333;
}
.em {
background-color: rgb(0, 238, 255);
color: rgb(255, 0, 34);
}
.bgc {
background-color: greenyellow;
}
</style>
</head>
<body>
<div class="box">php中文网</div>
<script>
let box = document.querySelector(".box");
console.log(box);
//添加class
box.classList.add("active");
//判断是否有class
console.log(box.classList.contains("box"));
//替换class
box.classList.replace("box", "em");
//移除class
box.classList.remove("em");
//toggle 有去无加
box.classList.toggle("bgc");
</script>
blur事件进行表单非空验证
示例代码:
//焦点移除密码不能为空
document.forms.login.password.onblur = function () {
if (this.value.length === 0) {
alert("密码不能为空");
return false;
}
};
更多相关文章
- Dagger-Android使用手册
- 整理出15个Android很有用的代码片段
- androidのMMS短信发送过程(一)
- Android(安卓)常用代码集合
- Android(安卓)开发中遇到的 bug(6)
- Android(安卓)学习——Android(安卓)菜单(OptionMenu)大全 建立
- Android录音时获取分贝值的方法代码实例
- android 播放音乐示例
- android中使用定时任务