doc: create accessing an element by ID
This commit is contained in:
1 parent
59b97480d4
commit
0b07bda836
1 file changed
+6
@@ -28,3 +28,9 @@ abbrlink: 18007
|
||||
- puppyImg.src 由浏览器设置为images/puppy.png
|
||||
- puppyImg.alt 由浏览器设置为"一个奇妙的小狗照片"
|
||||
- class或id,可用于在JS中选择项目
|
||||
|
||||
## 通过ID访问元素:
|
||||
```javascript
|
||||
let name = document.getElementById("id");
|
||||
```
|
||||
document.getElementById返回具有给定id的元素的DOM对象(注意,你可以不用填写"#")。
|
||||
Reference in new issue
Block a user