首先定义一个变量便于下面测试:var str = “xx351223441”; substring:str.substring(form,to):从字符串里截取下标为form到下标为to的字符串(不包括to对应的字符)alert(str.substring(2,6)) // 3512当form>to时,substring会把较小的参数作为第一参数 alert(str.substring(6,2)) //3512并且当其中某个参数值为负数时,substring会直接将负数转成0。 alert(str.substring(6,-2)) // xx351 slice:str.slice(star,end):从字符串里抽取下标为star到下标为end的字符串(不包括end对应的字符) alert(str.slice(2,6)) //3512当star>end时,slice会返回空字符串 alert(str.slice(6,2)) // null并且当其中某个参数值为负数时,slice会将此参数与字符串长度相加的结果作为参数 alert(str.slice(6,-2)) // 234且slice可以对数组操作。 substr:str.substr(star,length):从下标为star的字符串开始,截取长度为length的一个子字符串 alert(str.substr(2,6)) // 351223当star为负数时,substr会将此参数与字符串长度相加的结果作为参数 alert(str.substr(-6,2)) // 22当end为负数时,返回空字符串。 alert(str.substr(6,-2)) // null