搜索文档
首页
HTML/CSS
JavaScript
服务端开发
Java教程
移动端
数据库
当前位置:
首页
JavaScript
JavaScript 教程
JavaScript基础教程
源代码
清空
点击运行
<!DOCTYPE html> <html> <title>删除自身示例 - 基础教程(div.cn)</title> <body> <h1>JavaScript this 关键字</h1> <button>点击删除我</button> <p>点击改变我的背景颜色</p> <script> let btn = document.querySelector("button"); let para = document.querySelector("p"); btn.onclick = function() { this.style.display = "none"; }; para.onclick = function() { this.style.backgroundColor = "coral"; }; </script> </body> </html>
运行结果