直接看下面例子:
var test = ‘hello world‘; alert(test.slice(4,7)); //o w alert(test.substring(4,7)); //o w alert(test.substr(4,7)); //o world
如:
alert(test.substring(7,4)); //o w
测试代码如下:
var test = ‘hello world‘; alert(test.slice(-3)); //rld alert(test.substring(-3)); //hello world alert(test.substr(-3)); //rld alert(test.slice(3,-4)); //lo w alert(test.substring(3,-4)); //hel alert(test.substr(3,-4)); //空字符串
原文:http://www.cnblogs.com/faunjoe88/p/6344599.html