×
参考手册概览

JavaScript 对象

JavaScript Array 对象手册 JavaScript Array 对象JavaScript Boolean 对象JavaScript Date 对象JavaScript Math 对象JavaScript Number 对象JavaScript String 对象JavaScript RegExp 对象JavaScript 全局属性/函数JavaScript 运算符

Browser 对象

Window 对象Navigator 对象Screen 对象History 对象Location 对象

DOM 对象

HTML DOM DocumentHTML DOM 元素对象HTML DOM 属性对象HTML DOM 事件对象

HTML 对象

<a><area><audio><base><blockquote><body><button><canvas><col><colgroup><datalist><del><details><dialog><embed><fieldset><form><iframe><frameset ><img><ins><input> - button<input> - checkbox<input> - color<input> - date<input> - datetime<input> - datetime-local<input> - email<input> - file<input> - hidden<input> - image<input> - month<input> - number<input> - range<input> - password<input> - radio<input> - reset<input> - search<input> - submit<input> - text<input> - time<input> - url<input> - week<keygen><link><label><legend><li><map><menu><menuItem><meta><meter><object><ol><optgroup><option><param><progress><q><script><select><source><style><table><td><th><tr><textarea><title><time><track><video>

JavaScript substring() 方法


JavaScript String 对象JavaScript String 对象


定义和用法

substring() 方法用于提取字符串中介于两个指定下标之间的字符。

substring() 方法返回的子串包括 开始 处的字符,但不包括 结束 处的字符。

语法

string.substring(from, to)

参数 描述
from 必需。一个非负的整数,规定要提取的子串的第一个字符在 string Object 中的位置。
to 可选。一个非负的整数,比要提取的子串的最后一个字符在 string Object 中的位置多 1。
如果省略该参数,那么返回的子串会一直到字符串的结尾。


浏览器支持

Internet ExplorerFirefoxOperaGoogle ChromeSafari

所有主要浏览器都支持 substring() 方法


实例

实例

在本例中,我们将使用 substring() 从字符串中提取一些字符::

<script>

var str="Hello world!";
document.write(str.substring(3)+"<br>");
document.write(str.substring(3,7));

</script>

以上代码输出结果:

lo world!
lo w

尝试一下 »

JavaScript String 对象JavaScript String 对象


分类导航

关注微信下载离线手册

bootwiki移动版 bootwiki
(群号:472910771)