Prototype-dollarw-method

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

プロトタイプ-$ w()メソッド

$ w()関数は、文字列を配列に分割し、すべての空白を区切り文字として扱います。

構文

$w(String);

戻り値

文字列の配列。

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

      <script>
         function ShowValues() {
            var str = "Apples Bananas Kiwis";

           //Convert string into Array
            var arr = $w(str);
            arr.each(function(value) {
               alert(value);
            });
         }
      </script>
   </head>

   <body>
      <p>Click "Show Value" button to see the result</p>

      <form>
         <input type = "button" value = "Show Value" onclick = "ShowValues();"/>
      </form>

   </body>
</html>

出力