【C022081】下面是个输入框
当没有获取焦点时,显示灰色的提示信息:
当用户输入时,隐藏提示文字,且恢复为默认色:
当输入框失去焦点,如果输入为空,需还原提示信息:
要求: a) 写出HTML和CSS代码 b) 用JavaScript实现功能
西镜丶东瓶 2楼
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
<link rel="stylesheet" href="2.css">
</head>
<body>
<input type="text" placeholder="请输入内容">
<s cript type="text/javas cript" src="2.js"></s cript>
</body>
</html>
var inp=document.getElementsByTagName("input")[0];
inp.onblur=function() {
inp.setAttribute("placeholder","请输入内容");
}
inp.onfocus=function(){
inp.setAttribute("placeholder","");
}