js截取指定字符前面或后面的内容


function getCaption(obj,state) {
var index=obj.lastIndexOf("\-");
if(state==0){
obj=obj.substring(0,index);
}else {
obj=obj.substring(index+1,obj.length);
}
return obj;
}
var data = 'aaa-bbb'
//截取符号前面部分
getCaption(data,0) //输出aaa
//截取符号后面部分
getCaption(data,1) //输出bbb

原文链接:https://blog.csdn.net/caiyongshengCSDN/article/details/88420416


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM