原生JS修改html内容不影响绑定的点击事件 请认准insertAdjacentHTML、insertAdjacentText方法
生活随笔
收集整理的這篇文章主要介紹了
原生JS修改html内容不影响绑定的点击事件 请认准insertAdjacentHTML、insertAdjacentText方法
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
insertAdjacentText方法與 insertAdjacentHTML方法類似,只不過是插入純文本,參數相同
參數說明:
elementDOM.insertAdjacentHTML(where,html)
elementDOM:用于參照插入位置的html元素對象
where:插入位置。包括"beforeBegin"、"beforeEnd”、“afterBegin”、”afterEnd":
- beforeBegin?插入到標簽開始之前
- afterBegin?插入到標簽開始之后
- beforeEnd?插入到標簽結束之前
- afterEnd?插入到標簽結束之后
html:要插入的html代碼 或 Text內容
div.insertAdjacentHTML("beforeEnd", html);//插入到標簽結束標記前(常用1:在DOM內部最末端插入html)div.insertAdjacentHTML("afterBegin", html);//插入到標簽開始標記之后(常用2:在DOM內部最前面插入html)div.insertAdjacentHTML("beforeBegin", html);//插入到標簽開始前div.insertAdjacentHTML("afterEnd", html);//插入到標簽結束標記后
上面的代碼插入位置入下圖所示
總結
以上是生活随笔為你收集整理的原生JS修改html内容不影响绑定的点击事件 请认准insertAdjacentHTML、insertAdjacentText方法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 几个比较冷门的prototype扩展方法
- 下一篇: 几种和边框相关的CSS样式修改