doc: create a handy shortcut section
This commit is contained in:
1 parent
a1c4270f4b
commit
adcc2f2cad
1 file changed
+16
@@ -84,3 +84,19 @@ 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