js判断是否包含指定字符串

时间:2023-03-08 21:43:08

CreateTime--2017年2月28日09:37:06
Author:Marydon
js判断是否包含指定字符串

var inputValue = "thunder://piaohua.com";
//方法一:使用indexOf()方法实现
if (inputValue.indexOf("thunder://") >= 0) {
alert(1);
} //自定义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);
}
//实现
if (inputValue.startWith("thunder://")) {
alert(1);
}