84669 personnes étudient
152542 personnes étudient
20005 personnes étudient
5487 personnes étudient
7821 personnes étudient
359900 personnes étudient
3350 personnes étudient
180660 personnes étudient
48569 personnes étudient
18603 personnes étudient
40936 personnes étudient
1549 personnes étudient
1183 personnes étudient
32909 personnes étudient
innerHTML出来的是一个对象appendChild直接报错请问是为什么呢?
欢迎选择我的课程,让我们一起见证您的进步~~
1、document.body.innerHTML+=ele ----------> document.body.innerHTML+=ele.toString()2、appendChild的参数必须是一个Node节点。(https://developer.mozilla.org...)
当字符串和对象相加时,对象会先.toString(),所以你看到的 [object HTMLParagraphElement] 是ele.toString()的结果。
.toString()
ele.toString()
appendChild方法接收的是一个Node对象,即只接受像Element、Text、 Attribute等之类的,而now是一个Date类型。
appendChild
Node
now
1、document.body.innerHTML+=ele ----------> document.body.innerHTML+=ele.toString()
2、appendChild的参数必须是一个Node节点。
(https://developer.mozilla.org...)
字符串操作
当字符串和对象相加时,对象会先
.toString()
,所以你看到的 [object HTMLParagraphElement] 是ele.toString()
的结果。参数
appendChild
方法接收的是一个Node
对象,即只接受像Element、Text、 Attribute等之类的,而now
是一个Date类型。