电脑爱好者,提供IT资讯信息及各类编程知识文章介绍,欢迎大家来本站学习电脑知识。 最近更新 | 联系我们 RSS订阅本站最新文章
电脑爱好者
站内搜索: 
当前位置:首页>> Javascript>>javascript函数substr()作用及例子介绍:

javascript函数substr()作用及例子介绍

来源:网络 | 2008-2-11 | (有3784人读过)

substr()用法介绍

substr()方法用于从字符串中从指定的起始位置选取指定长度的一段字符.

3点注意:

Note: To extract characters from the end of the string, use a negative start number. 
注意:要从字符的末尾开始选取字符,用一个负的起始值。 

Note: The start index starts at 0. 
注意:默认的起始位置为0 

Note: If the length parameter is omitted, this method extracts to the end of the string. 
注意:如果没有指定选取的长度,默认选取自起始位置起剩下的所有字符 


substr()例子

In this example we will use substr() to extract some characters from a string: 
在本例中,我们将用substr()从一个字符串中选取一些字符: 

<script type="text/javascript"> 
var str="Hello world!"document.write(str.substr(3)) 
</script> 
  

The output of the code above will be: 
输出结果为: 

lo world! 
  
Javascript热门文章排行
网站赞助商
购买此位置

 

关于我们 | 网站地图 | 文档一览 | 友情链接| 联系我们

Copyright © 2003-2024 电脑爱好者 版权所有 备案号:鲁ICP备09059398号