$(function() { let pathName = window.location.pathname; $('.p_level1Item').each(function() { let index = $(this).index(); let curUrl = $('.p_level1Item:eq('+index+') a').attr('href'); if (pathName == curUrl) { $(this).addClass('active').siblings().removeClass('active'); } }); })