doc: create using a click event handler to open the box section

This commit is contained in:
Leon Xu committed 2021-08-31 16:02:53 -07:00
1 parent ac10edc2ac
commit aa0c1ec055
1 file changed
+16 -1
+16 -1
View File
@@ -145,4 +145,19 @@ function responseFunction(e) {
// we can access the click Event object here!
}
```
当事件发生时,将创建一个event对象并传递给事件侦听器。你可以"catch"此事件对象作为可选参数,以获取有关该事件的更多信息。
当事件发生时,将创建一个event对象并传递给事件侦听器。你可以"catch"此事件对象作为可选参数,以获取有关该事件的更多信息。
## 使用单击事件处理程序打开框
```html
<img id="mystery-box" src="question-block.png" alt="一个神秘的盒子">
<button id="box-btn">点击我!</button>
```
```javascript
let boxBtn = document.getElementById("box-btn");
boxBtn.addEventListener("click", openBox);
function openBox() {
let box = document.getElementById("mystery-box"); // 1、获取箱子图片
box.src = "star.png"; // 2、修改箱子图片的src属性!
}
```