我的意思是,比如以这个链接为例:http://forum.csdn.net/PointForum/Form/PostTopic.aspx 我要取它中间的 forum.csdn.net 这一部分,去掉前面的“http://”和第一个“/”符号后面的部分。 

解决方案 »

  1.   

      <script>
      alert("http://forum.csdn.net/PointForum/Form/PostTopic.aspx ".split('\/',3)[2]);
      </script>
      

  2.   

    对,假如前面本来就没有http://,怎么办?比如:<script>
      alert("forum.csdn.net/PointForum/Form/PostTopic.aspx ".split('\/',3)[2]);
    </script>
    谢谢。
      

  3.   

    在网页里取location.href都有http的吧
      

  4.   

      <script>
      alert("forum.csdn.net/PointForum/Form/PostTopic.aspx".match(/((\w+):\/\/)?([\w.]+)\/(\S*)/)[3]);
      </script>
      

  5.   

    已经根据junp2007的提示解决,谢谢大家。结贴。
      

  6.   

    function SetString(str,len)
    {
    var strlen = 0;
    var s = "";
    for(var i = 0;i < str.length;i++)
    {
            if(str.charCodeAt(i) > 128)
             strlen += 2;
            else
            strlen++;
            s += str.charAt(i);
            if(strlen >= len)
            return s + "...";
    }
    return s;
    }