js文本框input获取焦点和失去焦点
//需求:用户的获取焦点
//思路:用户的input按钮获取了插入条光标立刻删除内容。失去插入条光标显示文字
//获取事件源和相关元素
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
用户:<input type="text" name="jd" id="inp1" value="我是用户" /><br>
昵称:<label for="inp2">我是昵称</label><input type="text" name="tb" id="inp2"/><br>
密码:<input type="text" placeholder="我是密码"/>
</body>
<script type="text/javascript">
var inp1 = document.getElementById("inp1");
//绑定事件
inp1.onfocus =function(){
//书写驱动程序
if (this.value=="我是用户") {
this.value = "";
}
}
inp1.onblur = function(){
if (this.value==="") {
this.value = "我是用户";
}
}
</script>
</script>
</html>
原文链接:https://www.qiquanji.com/post/8210.html
本站声明:网站内容来源于网络,如有侵权,请联系我们,我们将及时处理。
版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。

