개념
var str = 'Mozilla';
console.log(str.substring(1, 3));
// expected output: "oz"
console.log(str.substring(2));
// expected output: "zilla"
현재 페이지에 클래스 추가하기
javascript, jquery を勉強したけどいつも難しい。
// http://127.0.0.1/06_menu/feature/index.html //"/"[2]기준으로 feture 를 가져온다.
var activeUrl = location.pathname.split("/")[2];
// 문자열의 앞 20번째 인덱스까지 자른후 다음 문자열 추출, 20이후의 문자열 추출
var activeSub = location.href.substring(20);
navList = $(".menu-list > li").find("> a");
subMenu = $('.sub-menu > li').find(">a");
navList.each(function(){
if( $(this).attr("href").split("/")[2] == activeUrl ) {
console.log($(this).attr("href").split("/")[2],activeUrl);
$(this).addClass("active");
};
});
subMenu.each(function() {
if ($(this).attr("href") == activeSub) {
$(this).addClass("active");
}
});
}