bind

作者: 真是个非常帅气的昵称呢 | 来源:发表于2019-10-09 10:45 被阅读0次
    <!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>
      <div id="div">
          <span>22222</span>
          <button>获取验证码</button>
          <span>3333333</span>
      </div>
      
      <script>
        class Btn{
          constructor(id){
            this.div=document.querySelector(id)
            this.btn=this.div.querySelector('button')
            this.btn.onclick=this.show.bind(this.btn,this)
          }
          show(that){
            this.innerHTML="HHHHHHHH"
            that.div.insertAdjacentHTML('beforebegin',"span之前")
          }
        } 
        new Btn("div")
      </script>
    </body>
    </html>
    

    相关文章

      网友评论

          本文标题:bind

          本文链接:https://www.haomeiwen.com/subject/astuuctx.html