JavaScript字符串对象substr方法入门实例(用于截取字符串)
JavaScriptsubstr方法
substr方法用于根据开始位置和长度截取字符串并返回截取部分字符串。其语法如下:
str_object.substr(start,length)
参数说明:
说明
str_object
要操作的字符串(对象)
start
必需。开始截取的位置,从0开始计算;如果为负数则从字符串末尾开始计算(经测试,某些浏览器版本下无效)
length
可选。指要截取的字符串长度,省略则至到字符串结束
提示:substr方法不符合ECMAscript标准,因此不建议使用。
substr方法实例
<scriptlanguage="JavaScript">
varstr="www.nhooo.com"; document.write(str.substr(4,5));
</script>