String.substring(start-index,stop-index)
- start-index: (Required - Numeric Value) - where to start the extraction
- stop-index : (Optional - Numeric Value) - where to stop the extraction
var str = "Hello World";
document.write(str.substring(4,8));
String.substr(start-index,length)
- start-index: (Required - Numeric Value) - where to start the extraction
- length : (Optional - Numeric Value) - how many characters to extract
var str = "Hello World";
document.write(str.substr(4,4));
Since JavaScript substr() is not cross-browser, I never use it.
–end–
本文介绍了JavaScript中用于字符串处理的两种方法:substring() 和 substr()。通过示例代码展示了如何使用这两种方法来截取字符串的不同部分。同时指出由于浏览器兼容性问题,作者不推荐使用 substr() 方法。
524

被折叠的 条评论
为什么被折叠?



