doc: create a handy shortcut section

This commit is contained in:
Leon Xu committed 2021-09-08 15:05:50 -07:00
1 parent a1c4270f4b
commit adcc2f2cad
1 file changed
+16
+16
View File
@@ -83,4 +83,20 @@ function init() {
// 在这里设置初始文档事件处理程序。
}
})();
```
### 方便的快捷函数
我们会在很多时候使用document.getElementById和document.querySelectorAll。声明一个快捷方式来帮助我们是很方便的。你可以在你的JS函数中使用以下内容(这些是拥有描述函数名称规则的例外)。
```javascript
function id(idName) {
return document.getElementById(idName);
}
function qs(selector) {
return document.querySelector(selector);
}
function qsa(selector) {
return document.querySelectorAll(selector);
}
```