Add a tag jump style rear interface

1, and using the substring lastIndexOf :
  substring () method for extracting specified character string intermediary between the two subscripts.

  substring () method returns the substring including the character at the beginning of, but does not include the character at the end.

  lastIndexOf () method returns the location of a specified string value of the last occurrence of the second parameter if the designated start, specify a location in the search string from back to front.

Code shows:

//侧边切换
$(".main-left-list").each(function () {
   var url = window.location.href;
    if (returnUrl($(this).children().attr("href"))==returnUrl(url)){
        $(this).addClass("rankingPlate");
    }
});
function returnUrl(href) {
    var number = href.lastIndexOf('/');
    return href.substring(number+1);
}

My Interface:
var url = / the User / Plate / 0/ 62
Note:
  Because I was depending on the last number and add to its style, so first of all get the current URL of the page to open, in my judgment whether its acquisition interface equal, if equal returnUrl call this function is the same as the numbers taken and to add style.
2, using substr
  substr () method to extract a specified number of index from the start of the start character in the string.

Code shows:

$(".rankScreenLi").each(function () {
    var url = window.location.href;
    if(returnUrlSub($(this).children().attr("href"))==returnUrlSub(url)){
        $(this).addClass("rankScreenStyle");
    }
});
function returnUrlSub(href) {
    return href.substr(-3,1);
}

** Note: ** This place is truncated character specified location.

to sum up:

I wrote two ways for a reason, I just started using a second method, but the interface is not a pass over the digital single digit, so use the second method there will be a lot of bug. The first method is the last to find a '/' taken all the strings behind it and compare.

Published 54 original articles · won praise 7 · views 3237

Guess you like

Origin blog.csdn.net/weixin_43690348/article/details/100856017