原型- inspect() 方法



此方法返回元素的面向除錯的字串表示形式。Prototype 為內建和庫定義的多種型別(如 String、Array、Enumerable 和 Hash)提供 inspect 方法,這些方法試圖為各自的型別提供最有用的字串表示形式。

  • undefinednull 表示為這些值。

  • 其他型別查詢 inspect 方法:如果有,則使用此方法;否則,會恢復到 toString 方法。

語法

element.inspect();

返回值

返回插入內容後 HTML 元素。

示例

<html>
   <head>
      <title>Prototype examples</title>
      <script type = "text/javascript" src = "/javascript/prototype.js"></script>
      
      <script>
         function showResult() {
            var str = $('golden-delicious').inspect();
            alert("$('golden-delicious').inspect(): " + str );
      
            var str = $('mutsu').inspect();
            alert("$('mutsu').inspect() : " + str );
         
            var str = $('mutsu').next().inspect();
            alert("$('mutsu').next().inspect() : " + str );
         }
      </script>
   </head>

   <body>
      <p>Click the button to see the result.</p>
      
      <ul>
         <li id = "golden-delicious">Golden Delicious</li>
         <li id = "mutsu" class = "yummy apple">Mutsu</li>
         <li id = "mcintosh" class = "yummy">McIntosh</li>
         <li</li>
      </ul>
      <br />
      
      <input type = "button" value = "Click" onclick = "showResult();"/>
   </body>
</html>

輸出

prototype_element_object.htm
廣告
© . All rights reserved.