Prototype-string-capitalize

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

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

このメソッドは、文字列の最初の文字を大文字にし、他のすべてを小文字にします。

構文

string.capitalize();

戻り値

文字列を返します。

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

      <script>
         function showResult() {
            var str = 'hello';
            alert("hello.capitalize() : " + str.capitalize() );
            str = 'HELLO WORLD!';
            alert("HELLO WORLD!.capitalize() : " + str.capitalize() );
         }
      </script>
   </head>

   <body>
      <p>Click the button to see the result.</p>
      <br/>
      <br/>
      <input type = "button" value = "Result" onclick = "showResult();"/>
   </body>
</html>

出力