<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<input type="text" name="name" value="hello" />
<script>
var text = document.querySelector('input');
text.onfocus = function () {
console.log('得到了焦点');
if (this.value == 'hello') {
this.value = 'see you';
}
this.style.color = '#333';
}
text.onblur = function () {
console.log('失去了焦点');
if (this.value == 'see you') {
this.value = 'hello';
}
this.style.color = '#999';
}
</script>
</body>
</html>
html获得焦点和失去焦点
于 2022-05-05 21:58:52 首次发布