DOM - 實體物件屬性 - publicId



此屬性 publicId 返回關聯實體的公共識別符號或返回 null。

語法

以下是屬性 publicId 用法的語法。

document.doctype.publicId;

示例

notation.xml 內容如下 −

<?xml version = "1.0" encoding = "UTF-8" standalone = "no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<address id = "firstelement">
   <name>Tanmay Patil</name >
   <company>TutorialsPoint</company>
   <phone>(011) 123-4567</phone>
</address>

以下示例演示屬性 publicId 的用法 −

<!DOCTYPE html>
<html>
   <head>
      <script>
         function loadXMLDoc(filename) {
            if (window.XMLHttpRequest) {
               xhttp = new XMLHttpRequest();
            } else // code for IE5 and IE6 {
               xhttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            xhttp.open("GET",filename,false);
            xhttp.send();
            return xhttp.responseXML;
         }
      </script>
   </head>
   <body>
      <script>
         xmlDoc = loadXMLDoc("/dom/notation_xhtml.xml");
         document.write("<b>publicid :</b> "+xmlDoc.doctype.publicId);
      </script>
   </body>
</html>

執行

entity_publicid.html 為檔名儲存在伺服器路徑上(此檔案和 notation.xml 應在伺服器上的同一路徑下)。我們將獲得如下所示的輸出 −

publicid : -//W3C//DTD XHTML 1.1//EN 
dom_entity_object.htm
廣告
© . All rights reserved.