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 = 'https://www.cnblogs.com/qiantao/p/aaa-bbb' //截取符號前面部分 getCaption(data,0) //輸出aaa //截取符號后面部分 getCaption(data,1) //輸出bbb
原文鏈接:https://blog.csdn.net/caiyongshengCSDN/article/details/88420416
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/162088.html
標籤:JavaScript
上一篇:vue 中 px轉vw的用法
