怎样判断字符串中含有http://               http大小写都可以

解决方案 »

  1.   

    if(/http:\/\//i.test("字符串"))
    {
    //包含
    }
    else
    {
    //不包含
    }
      

  2.   

    if(/http:\/\//gi.test("字符串"))
    {
    //包含
    }
    else
    {
    //不包含
    }
      

  3.   

    <script>
      var str="http://aaa.s";
     
      if(str.indexOf("http://")!=-1){alert("yes")}
      else{alert("no")}
        var str="http:aaa.s";
    if(str.indexOf("http://")!=-1){alert("yes")}
      else{alert("no")}
    </script>
      

  4.   

    <script>
      var str="http://aaa.s";
      if(str.indexOf("http://")!=-1||str.indexOf("HTTP://")!=-1)
      {alert("yes")}
      else{alert("no")}
      var str2="HTTP://aaa.s";  
      if(str.indexOf("http://")!=-1||str.indexOf("HTTP://")!=-1)
      {alert("yes")}
      else{alert("no")}
    </script>