如何編寫指令碼根據可用性使用 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