<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
密码:<input type="password" name="password" placeholder="密码">
<script src="jquery-1.12.4.js"></script>
<script>

    $(function () {
        $("input").onfocus(function () {
                this.value='';
                this.type='password';
        });
        $("input").onblur(function () {
                this.type = 'text';
                this.value = '请输入密码';
        })
    });

</script>
</body>
</html>

这个是报错的,

jquery遇到的坑

jquery遇到的坑

由于在juery中对方法进行了封装,没有了onfocus方法

所以需要修改代码变成一下:

  $(function () {
        $("input").focus(function () {
                this.value='';
                this.type='password';
        });
        $("input").blur(function () {
                this.type = 'text';
                this.value = '请输入密码';
        })
    });

 

相关文章:

  • 2021-08-16
  • 2021-05-27
  • 2021-04-21
  • 2021-05-19
  • 2021-06-29
  • 2021-09-08
  • 2021-07-24
  • 2021-11-24
猜你喜欢
  • 2021-11-24
  • 2021-05-29
  • 2021-10-08
  • 2022-12-23
  • 2021-09-15
  • 2021-06-17
  • 2021-10-03
相关资源
相似解决方案