例如:
var str = http://10.2.20.87/file/upload
如何获取第2次出现的反斜杠的位置

解决方案 »

  1.   


    var s = 'http://10.2.20.87/file/upload';
    alert(s.replace('/','a').indexOf('/'))
      

  2.   


    var s = "http://10.2.20.87/file/upload";

    function getIndex(url) {
    var temp = url.match(/[^\/]+(\/)+[^\/]+\//g);
    return temp? Math.max(0, temp[0].length - 1) : -1;
    }
    alert(getIndex(s));
      

  3.   

     var str = "http://10.2.20.87/file/upload";
    alert(str.indexOf('/'));
     alert(str.indexOf('/',str.indexOf('/')+1));
      

  4.   

    注意indexOf的用法,第一个参数,是找的字符串,第二个参数是起始位置
      

  5.   


    var s = 'var str = http://10.2.20.87/file/upload';
    alert(s.split(/\//)[2]);
      

  6.   

     var str = "http://10.2.20.87/file/upload";
            alert(str.match(/([^\/]*\/){2}([^\/]*)/)[2]);