我有一个网址:比如http://192.168.1.1/Region/index.html,
现在我如何取得中间的值,也就是192.168.1.1

解决方案 »

  1.   

    js有没有现成的函数呀?最前面也可能是ftp://等其他的协议。
      

  2.   

    var href="http://192.168.1.1/Region/index.html";
    var nohttp=href.substring(href.indexOf("//")+2,href.length)
    var ip=nohttp.substring(0,nohttp.indexOf("/"));
    alert(ip);
      

  3.   

    window.location.hostname 是取当前网页的IP
      

  4.   


    var url="http://192.168.1.1/Region/index.html";
    var reg = new RegExp("http:\/\/([^\/]+)","ig");
    var arr = reg.exec(url);
    alert(RegExp.$1);
      

  5.   

    如果网址中带有端口号:比如http://192.168.1.1:80/Region/index.html,怎么取192.168.1.1:80