js中substring该方法返回一个String对象的一个子集。

1、语法
string.substring(indexA, [indexB])1复制代码类型:[javascript]
下面是参数的详细信息:
indexA: 介于0和1小于字符串的长度的整数。
indexB: (可选)介于0和字符串的长度的整数。
2、返回值:
js中substring方法返回基于给定参数的新的子字符串。
3、js截取字符串方法例子:
<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>4、结果:
(1,2): p (0,10): Apples are (5): s are round, and apples are juicy.富士康内部推荐
版权声明:除非特别标注,否则均为本站原创文章,转载时请以链接形式注明文章出处。
还木有评论哦,快来抢沙发吧~