1,正则

var str=new RegExp("http");
str.test("httpadfsd");//test方法返回值为(true或者false)

2 indexOf();

var newStr=str.indexOf("http");

 if(newStr==0){
   console.log("字符串是以http开头的!")
}
if(newStr==-1){

  console.log("字符串不是以http开头的!")

}

相关文章:

猜你喜欢
  • 2021-11-21
  • 2021-06-20
  • 2022-12-23
  • 2022-02-06
  • 2022-02-13
  • 2022-12-23
  • 2022-01-07
相关资源
相似解决方案