<!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>
网友评论