此方法返回String对象的子集。
string.substring(indexA, [indexB])
indexA - 是一个介于0和小于字符串长度之间的整数。
indexB - (可选)介于0和字符串长度之间的整数。
substring方法根据给定的参数返回新的子字符串。
<html> <head> <title>JavaScript String substring() Method</title> </head> <body> <script type="text/javascript"> var str="Apples are round, and apples are juicy."; document.write("(1,2): " + str.substring(1,2)); document.write("<br />(0,10): " + str.substring(0, 10)); document.write("<br />(5): " + str.substring(5)); </script> </body> </html>
运行上面代码输出
(1,2): p (0,10): Apples are (5): s are round, and apples are juicy.
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)