doc: create a handy shortcut section
This commit is contained in:
1 parent
e893648d6b
commit
063f282bcd
1 file changed
+16
@@ -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);
|
||||
}
|
||||
```
|
||||
Reference in new issue
Block a user