Prototype - inspect() 方法

此方法返回元素的调试导向字符串表示形式。Prototype 为许多类型(包括内置类型和库定义类型)提供了检查方法,例如 String、Array、Enumerable 和 Hash,这些方法试图为各自的类型提供最有用的字符串表示形式。

  • 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>单击按钮查看结果。</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.html