JS 点击input文本框,文字消失

http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>建站学JS点击输入框,框内文字消失实例www.jzxue.com</title>
<script type="text/javascript">
//得到焦点时触发事件
function OnFocusFun(element,elementvalue)
{
if(element.value==elementvalue)
{
element.value="";
element.style.color="#000";
}
}
//离开输入框时触发事件
function OnBlurFun(element,elementvalue)
{
if(element.value==""||element.value.replace(/\s/g,"")=="")
{
element.value=elementvalue;
element.style.color="#999";
}
}
</script>
</head>
<body>
<div>欢迎学习建站学点击<strong>输入框</strong>框内文字消失实例</div>
<div>
<span>账号:</span>
<input type="text" value="请输入用户名" id="UserId" onfocus="OnFocusFun(this,'请输入用户名')" style="color:#999"  onblur="OnBlurFun(this,'请输入用户名')"/>
</div>
<div>
<span>密码:</span>
<input type="text" value="请输入密码" id="Password" onfocus="OnFocusFun(this,'请输入密码')" onblur="OnBlurFun(this,'请输入密码')" style="color:#999" />
</div>
</body>
</html>

经验可以积累,但梦想永远不能磨灭
原文地址:https://www.cnblogs.com/lancee/p/2235867.html