如何編寫一個指令碼以便根據其可用性使用 W3C DOM 或 IE 4 DOM?
如果你想編寫一個指令碼,該指令碼可以靈活使用 W3C DOM 或 IE 4 DOM(取決於它們的可用性),那麼你可以使用一個功能測試方法,該方法首先檢查方法或屬性的存在,以確定瀏覽器是否具備你期望的功能。
以下是顯示相同內容的程式碼片段 −
if (document.getElementById) {
// If the W3C method exists, use it
}
else if (document.all) {
// If the all[] array exists, use it
}
else {
// Otherwise use the legacy DOM
}
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP