當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


HTML DOM implementation用法及代碼示例


HTML中的DOM實現屬性用於返回與當前文檔關聯的DOMImplementation對象。 DOMImplementation是表示提供不依賴於任何特定文檔的對象的方法的接口。

用法:

document.implementation

返回值:它返回文檔實現對象。


範例1:

<!-- HTML code to check the document 
has HTML DOM 1.0 feature -->
<!DOCTYPE html> 
<html> 
    <head> 
        <title> 
            HTML DOM implementation Property 
        </title> 
          
        <script> 
            function DomFunction() { 
                var obj = document.implementation; 
                document.getElementById("demo").innerHTML  
                    = obj.hasFeature("HTML", "1.0"); 
            } 
        </script> 
    </head> 
      
    <body> 
        <h2>HTML DOM implementation Property</h2> 
          
        <p>Click on button to check the document 
        has HTML DOM 1.0 feature</p> 
          
        <button onclick = "DomFunction()"> 
            Click Here! 
        </button> 
          
        <p id = "demo"></p> 
    </body> 
</html>                    

輸出:
之前單擊按鈕:

單擊按鈕後:

範例2:

<!DOCTYPE html> 
<html> 
    <head> 
        <title> 
            HTML DOM implementation Property 
        </title> 
    </head> 
      
    <body> 
        <h2>HTML DOM implementation Property</h2> 
        <script> 
            var DOM_Name = "HTML"; 
            var DOM_Ver = "1.0"; 
            var GFG = document.implementation.hasFeature(  
                        DOM_Name, DOM_Ver); 
              
            alert( "DOM " + DOM_Name + " " + DOM_Ver  
                + " supported? " + GFG ); 
        </script> 
    </body> 
</html>                                

輸出:
dom

支持的瀏覽器:下麵列出了DOM實現屬性支持的瀏覽器:

  • 穀歌瀏覽器
  • IE瀏覽器
  • 火狐瀏覽器
  • Opera
  • 蘋果瀏覽器


相關用法


注:本文由純淨天空篩選整理自AlieaRizvi大神的英文原創作品 HTML | DOM implementation Property。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。