javascript中的startWith和endWith的幾種實現方法_javascript技巧
來源:懂視網
責編:小采
時間:2020-11-27 21:09:19
javascript中的startWith和endWith的幾種實現方法_javascript技巧
javascript中的startWith和endWith的幾種實現方法_javascript技巧:JavaScript采用正則表達式實現startWith、endWith效果函數 代碼如下:String.prototype.startWith=function(str){ var reg=new RegExp(^+str); return reg.test(this); } String.prototype.endWith=fu
導讀javascript中的startWith和endWith的幾種實現方法_javascript技巧:JavaScript采用正則表達式實現startWith、endWith效果函數 代碼如下:String.prototype.startWith=function(str){ var reg=new RegExp(^+str); return reg.test(this); } String.prototype.endWith=fu

JavaScript采用正則表達式實現startWith、endWith效果函數
代碼如下:
String.prototype.startWith=function(str){
var reg=new RegExp("^"+str);
return reg.test(this);
}
String.prototype.endWith=function(str){
var reg=new RegExp(str+"$");
return reg.test(this);
}
JavaScript實現startWith、endWith效果函數
代碼如下:
聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com
javascript中的startWith和endWith的幾種實現方法_javascript技巧
javascript中的startWith和endWith的幾種實現方法_javascript技巧:JavaScript采用正則表達式實現startWith、endWith效果函數 代碼如下:String.prototype.startWith=function(str){ var reg=new RegExp(^+str); return reg.test(this); } String.prototype.endWith=fu