Prototype-element-identify

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

プロトタイプ-特定()メソッド

このメソッドは、要素のid属性が存在する場合はそれを返すか、一意の自動生成されたidを設定して返します。

構文

element.identify();

戻り値

HTML要素IDを返します。

<html>
   <head>
      <title>Prototype examples</title>
      <script type = "text/javascript" src = "/javascript/prototype.js"></script>

      <script>
         function showResult() {
            var str = $('apple').identify();
            alert("Apple's ID: " + str );
            var str = $('apple').next().identify()
            alert("Orange's ID: " + str );
         }
      </script>
   </head>

   <body>
      <p>Click the button to see the result.</p>

      <ul>
         <li id = "apple">apple</li>
         <li>orange</li>
      </ul>
      <br/>

      <input type = "button" value = "Click" onclick = "showResult();"/>
   </body>
</html>

出力