重要事项:与 slice() 和 substr() 方法不同的是,substring() 不接受负的参数。
实例
例子 1
在本例中,我们将使用 substring() 从字符串中提取一些字符:
<script type="text/javascript">
var str="Hello world!"
document.write(str.substring(3)
)
</script>
输出:
lo world!
例子 2
在本例中,我们将使用 substring() 从字符串中提取一些字符:
<script type="text/javascript">
var str="Hello world!"
document.write(str.substring(3,7)
)
</script>
输出:
lo w