Dom-processinginstruction-target

提供:Dev Guides
移動先:案内検索

DOM-ProcessingInstructionオブジェクトの属性-ターゲット

属性_target_は、命令またはデータが向けられるアプリケーションを識別します。

構文

_target_属性を使用するための構文は次のとおりです。

ProcessingInstruction.target
S.No. Parameter & Description
1

target

命令またはデータの送信先のアプリケーションを識別します。

次の例は、_target_属性の使用方法を示しています-

<!DOCTYPE html>
<html>
   <head>
      <script>
        //loads the xml string in a dom object
         function loadXMLString(t) {
           //for non IE browsers
            if (window.DOMParser) {
              //create an instance for xml dom object
               parser = new DOMParser();
               xmlDoc = parser.parseFromString(t,"text/xml");
            } else//code for IE {
              //create an instance for xml dom object
               xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
               xmlDoc.async = false;
               xmlDoc.loadXML(t);
            }
            return xmlDoc;
         }
         function get_firstChild(p) {
            a = p.firstChild;
            return a;
         }
      </script>
   </head>
   <body>
      <script>
         var xml = "<Employee>";
         xml = xml+"<FirstName>";
         xml = xml+"<?piTarget piData more piData?>";
         xml = xml+"</FirstName>";

         xml = xml+"</Employee>";

        //calls the loadXMLString() with "text" function and store the xml dom in a variable
         var xmlDoc = loadXMLString(xml);

         var x = get_firstChild(xmlDoc.getElementsByTagName("FirstName")[0]);
         document.write("First child is : ");
         document.write(x.nodeName);

        //the following should be "piData more piData"
         alert(x.data);

        //the following should be "piTarget"
         alert(x.target);
      </script>
   </body>
</html>

実行

このファイルを_dom_processinginstruction_target_としてサーバーパスに保存します。 次のように出力を取得します-

PI demo