DOM API是否提供实现Node接口的HTMLTitle对象?DOM API是否提供实现Node接口的HTMLTitle对象?
document.title只返回标题的字符串部分。
typeof(document.title)
"string"
虽然其它属性,如document.head
是HTMLHeadElement
对象和document.doctype
是DocumentType
对象和二者实现节点接口。
DOM API是否提供实现Node接口的HTMLTitle对象?DOM API是否提供实现Node接口的HTMLTitle对象?
document.title只返回标题的字符串部分。
typeof(document.title)
"string"
虽然其它属性,如document.head
是HTMLHeadElement
对象和document.doctype
是DocumentType
对象和二者实现节点接口。
document.title
代表当前文档的标题字符串。元素的接口可以通过访问:
var tit = document.createElement('title')
typeof
是不要让内部的类名的正确方法。使用Object.prototype.toString
代替:
Object.prototype.toString.call(tit);
// returns "[object HTMLTitleElement]"
document.title给你一个字符串作为说明。
如果你想要的标题元素只使用document.getElementsByTagName
var title = document.getElementsByTagName("title")[0]
tit.toString()也应该返回同样的事情。我对吗? – 2012-04-05 20:08:28
@Praveen这是依赖于实现的。 '.toString()'方法可以被覆盖。例如,HTMLAnchorElement的'.toString()'方法返回'href'属性的值。最安全的方法是使用我的答案中提到的方法。另一个例子:''x“.toString()'显示'x',而'Object.prototype.toString.call(”x“)'显示'[object String]'。 – 2012-04-05 20:10:42
你18岁吗? – 2012-04-05 20:16:35