$(function () { var scp = $(".subNavList,.proSubNav") if ($(window).width() < 798) { // 移动端要做的事 // 子集全部隐藏 scp.find('.p_childBox').addClass('hide'); // 导航的展示与隐藏 $('.p_btn-show', scp).on('click', function () { $('.p_category', scp).toggleClass("animate") }); $('.p_btn-hide', scp).on('click', function () { $('.p_category', scp).toggleClass("animate") }) // 导航子集的展示与隐藏 scp.find('.js_categoryBox').on('click', '.js_clickbtn', function () { var $this = $(this); //控制同级互斥 $this.closest('.p_parentBox').siblings('.p_parentBox').children('.p_childBox').addClass('hide') .siblings('div').children('.js_clickbtn').removeClass('icon-arrow_down').addClass('icon-arrow_up'); //展开收起 if ($this.hasClass('icon-arrow_down')) { //收起 $this.removeClass('icon-arrow_down').addClass('icon-arrow_up'); $this.closest('.p_parentBox').children('.p_childBox').addClass('hide'); } else { //展开 $this.removeClass('icon-arrow_up').addClass('icon-arrow_down'); $this.closest('.p_parentBox').children('.p_childBox').removeClass('hide'); } }) } var href = location.pathname + location.search; if (!href) return; scp.find('a').each(function (index, ele) { var hrefa = $(ele).attr('href'); if (hrefa == href) { $(ele).addClass("active"); $(ele).parents(".p_parentBox").children().children("a.p_title ").addClass("active"); } }) });