什么document.body等于同等类型和等值比较?

时间:2018-03-08 15:10:00

标签: javascript

test_series.str[-2:].upper()

如果我这样比较:document.getElementById("demo").innerHTML = document.body //returns [object HTMLBodyElement]返回true。但如果我与document.body == "[object HTMLBodyElement]"比较,我认为类型不相等。如果我这样尝试:===返回false。或者如果这样:document.body === [HTMLBodyElement]也返回false。如果我希望此返回true,document.body === HTMLBodyElement的值是多少:x

1 个答案:

答案 0 :(得分:1)

为什么要将html的对象与字符串进行比较?

document.body是一个对象。

如果你想比较它,你需要将它与类似物体进行比较



let body=document.body
console.log(document.body===body)
console.log(typeof document.body=="object");
console.log(document.body == "[object HTMLBodyElement]"&& typeof document.body==="object")