[08--DOM] 搜索框获取焦点
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<input type="text" id="d1" value="请输入关键字" onfocus="fo()" onblur="bl()" >
<script>
var a1Ele=document.getElementById("d1")
function fo() {
var val = a1Ele.value
if (val=="请输入关键字"){
a1Ele.value=""
}
}
function bl() {
var val = a1Ele.value
val=val.trim()
if (val==""){
a1Ele.value="请输入关键字"
}
}
</script>
</body>
</html>