jquery遇到的坑

<!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>

这个是报错的,

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

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

  $(function () {
        $("input").focus(function () {
                this.value='';
                this.type='password';
        });
        $("input").blur(function () {
                this.type = 'text';
                this.value = '请输入密码';
        })
    });
原文地址:https://www.cnblogs.com/xiufengchen/p/10410667.html