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

更新於: 2020 年 6 月 23 日

85 次閱讀

開啟你的職業生涯

完成課程獲得認證

開始學習
廣告
© . All rights reserved.