File tree Expand file tree Collapse file tree 1 file changed +6
-7
lines changed Expand file tree Collapse file tree 1 file changed +6
-7
lines changed Original file line number Diff line number Diff line change @@ -295,7 +295,7 @@ test.isConnected // true
295
295
296
296
### Node.prototype.appendChild()
297
297
298
- ` appendChild ` 方法接受一个节点对象作为参数,将其作为最后一个子节点,插入当前节点。该方法的返回值就是插入文档的子节点。
298
+ ` appendChild() ` 方法接受一个节点对象作为参数,将其作为最后一个子节点,插入当前节点。该方法的返回值就是插入文档的子节点。
299
299
300
300
``` javascript
301
301
var p = document .createElement (' p' );
@@ -304,17 +304,16 @@ document.body.appendChild(p);
304
304
305
305
上面代码新建一个` <p> ` 节点,将其插入` document.body ` 的尾部。
306
306
307
- 如果参数节点是 DOM 已经存在的节点,` appendChild ` 方法会将其从原来的位置,移动到新位置。
307
+ 如果参数节点是 DOM 已经存在的节点,` appendChild() ` 方法会将其从原来的位置,移动到新位置。
308
308
309
309
``` javascript
310
- var element = document
311
- .createElement (' div' )
312
- .appendChild (document .createElement (' b' ));
310
+ var div = document .getElementById (' myDiv' );
311
+ document .body .appendChild (div);
313
312
```
314
313
315
- 上面代码的返回值是 ` <b></b> ` ,而不是 ` <div></div> ` 。
314
+ 上面代码中,插入的是一个已经存在的节点 ` myDiv ` ,结果就是该节点会从原来的位置,移动到 ` document.body ` 的尾部 。
316
315
317
- 如果` appendChild ` 方法的参数是` DocumentFragment ` 节点,那么插入的是` DocumentFragment ` 的所有子节点,而不是` DocumentFragment ` 节点本身。返回值是一个空的` DocumentFragment ` 节点。
316
+ 如果` appendChild() ` 方法的参数是` DocumentFragment ` 节点,那么插入的是` DocumentFragment ` 的所有子节点,而不是` DocumentFragment ` 节点本身。返回值是一个空的` DocumentFragment ` 节点。
318
317
319
318
### Node.prototype.hasChildNodes()
320
319
You can’t perform that action at this time.
0 commit comments