<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<meta charset="utf-8" />
</head>
<body>
<input /><input /><input /><input /><input /><input /><input />
<script type="text/javascript">
window.onload = function () {
var txtObjs = document.getElementsByTagName('input');
for (var i = 0; i < txtObjs.length; i++) {
if (txtObjs[i].type == 'text') {
//注册失去焦点的事件
txtObjs[i].onblur = function () {
if (this.value.length == 0) {
this.style.backgroundColor = 'red';
}
else {
this.style.backgroundColor = 'white';
}
};
}
}
};
</script>
</body>
</html>
动态操作CSS文本框失去焦点变颜色(注册onblur事件)
最新推荐文章于 2023-12-24 22:05:32 发布