是否可以在第一个字符后获取所有字符串?
var val = 'asdasd:111122:123123123';
var response = val.substring(val.lastIndexOf(":")+1);
alert(response ); // "123123123"
// Would like: ":111122:123123123"
谢谢!
答案 0 :(得分:4)
使用indexOf(...)
代替lastIndexOf(...)
如果要包含":"
,请不要在索引中添加一个。
像这样:
var val = 'asdasd:111122:123123123';
var response = val.substring(val.indexOf(":"));
alert(response); // ":111122:123123123"

答案 1 :(得分:0)
var mobileWithCode="+91-9842505145";//mobile value with nation code
mobile = mobileWithCode.substring(mobileWithCode.indexof("-"));
alert(mobile);
答案 2 :(得分:-1)
只需删除+1并继续您的代码将正常工作
var response = val.substring(val.lastIndexOf(":"));
alert(response); // Would Become: ":111122:123123123"