JavaScript 字符串 string substr 子字符串方法


JavaScript 字符串 string substr 子字符串方法

<html>
   <head>
      <title>JavaScript String substr() Method</title>
   </head>

   <body>

      <script type = "text/javascript">
         var str = "Apples are round, and apples are juicy.";

         document.write("(1,2): "    + str.substr(1,2));
         document.write("<br />(-2,2): "   + str.substr(-2,2));
         document.write("<br />(1): "      + str.substr(1));
         document.write("<br />(-20, 2): " + str.substr(-20,2));
         document.write("<br />(20, 2): "  + str.substr(20,2));
      </script>

   </body>
</html>