<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <input type="text" name="" id="input" value="" />
        <h1></h1>
        <h3 id="username"></h3>
        <h4 id="age"></h4>
        
        <script type="text/javascript">
            var inputText = document.querySelector('#input')
            var h1 = document.querySelector('h1')
            var h3 = document.querySelector('#username')
            var age = document.querySelector('#age')
            
            inputText.oninput = function(){
                var value =  inputText.value
                h1.innerHTML = value;
            }
            
            
            var obj = {
//                name:'张三',
                age:14,
                set name(value){
//                    console.log(value)
                    this._name = value
                    h3.innerHTML = this._name
                },
                get name(){
                    return this._name
                },
                
            }
            
            console.log(obj)
            //setter,getter//es6,es2015标准
            //在给对象属性赋值,或者是获取对象属性的时候,会调用setter、getter两个方法
        </script>
    </body>
</html>

 

相关文章:

  • 2021-06-20
  • 2021-08-31
  • 2021-06-20
猜你喜欢
  • 2021-12-24
  • 2022-12-23
  • 2021-05-22
  • 2021-04-30
  • 2021-10-13
相关资源
相似解决方案