欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

各种协议与HTTP协议的关系

程序员文章站 2022-07-12 21:57:34
...

defineProperty

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <input type="text" id="username">
    <span id="use"></span>
    <script>
        var obj = {
            psw : "1234"
        };
        Object.defineProperty(obj,"username",{
            get: function(){
                console.log("get init");
            },
            set: function(val){
                console.log("set init");
                document.getElementById("use").innerText = val;
                document.getElementById("username").value = val;
            }
        })

        document.getElementById("username").addEventListener("keyup",function(){
            obj.username = event.target.value;
        })
    </script>
</body>
</html>