首页 > Web开发 > 详细

js判断字符串是否包含http

时间:2020-08-04 12:50:58      阅读:443      评论:0      收藏:0      [点我收藏+]

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开头的!")

}

js判断字符串是否包含http

原文:https://www.cnblogs.com/stronger-xsw/p/13432460.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!