需求:京东的获取焦点
思路:京东的input按钮获取了插入条光标立刻删除内容。失去插入条光标显示文字
获取事件源和相关元素

 

<body>
京东:<input type="text" name="jd"  /><br>
淘宝:<label for="inp2">我是淘宝</label><input type="text" name="tb" >
placeholder:<input type="text" placeholder="我是placeholder"/>

<script>
//需求:京东的获取焦点
//思路:京东的input按钮获取了插入条光标立刻删除内容。失去插入条光标显示文字
//获取事件源和相关元素
var inp1 = document.getElementById("inp1");
//绑定事件
inp1.onfocus =function(){

//书写驱动程序
if (this.value=="我是京东") {
    this.value = "";
}
}
inp1.onblur = function(){
if (this.value==="") {
    this.value = "我是京东";
}
}

</script>

 

相关文章:

  • 2021-12-21
  • 2021-12-09
  • 2021-12-19
  • 2021-07-05
  • 2022-12-23
  • 2021-12-19
猜你喜欢
  • 2022-12-23
  • 2021-12-19
  • 2021-12-19
  • 2022-12-23
  • 2021-07-03
  • 2022-12-23
  • 2021-12-19
相关资源
相似解决方案