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