第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

將 jQuery 轉(zhuǎn)換為 JS

將 jQuery 轉(zhuǎn)換為 JS

我有以下 jQuery 代碼用于我的導(dǎo)航響應(yīng),我需要將其轉(zhuǎn)換為常規(guī)的 Javascript。我試圖了解它是如何removeAttr與兒童一樣有效的。有誰(shuí)知道如何將以下代碼轉(zhuǎn)換為純 JavaScript 嗎?let responsiveMenu = function() {  var menuType = 'desktop';    $(window).on('load resize', function() {    var currMenuType = 'desktop';    if (matchMedia('only screen and (max-width: 991px)').matches) {      currMenuType = 'mobile';    }    if (currMenuType !== menuType) {      menuType = currMenuType;      if (currMenuType === 'mobile') {        var $mobileMenu = $('#mainnav').attr('id', 'mainnav-mobi').hide();        var hasChildMenu = $('#mainnav-mobi').find('li:has(ul)');        $('#header #site-header-inner').after($mobileMenu);        hasChildMenu.children('ul').hide();        hasChildMenu.children('a').after('<span class="btn-submenu"></span>');        $('.btn-menu').removeClass('active');      } else {        var $desktopMenu = $('#mainnav-mobi').attr('id', 'mainnav').removeAttr('style');        $desktopMenu.find('.submenu').removeAttr('style');        $('#header').find('.nav-wrap').append($desktopMenu);        $('.btn-submenu').remove();      }    }  });  $('.mobile-button').on('click', function() {    $('#mainnav-mobi').slideToggle(300);    $(this).toggleClass('active');  });  $(document).on('click', '#mainnav-mobi li .btn-submenu', function(e) {    $(this).toggleClass('active').next('ul').slideToggle(300);    e.stopImmediatePropagation()  });};
查看完整描述

2 回答

?
交互式愛(ài)情

TA貢獻(xiàn)1712條經(jīng)驗(yàn) 獲得超3個(gè)贊

嘗試一下這個(gè)


const load_resize = function() {

  var currMenuType = 'desktop';

  if (matchMedia('only screen and (max-width: 991px)').matches) {

    currMenuType = 'mobile';

  }


  if (currMenuType !== menuType) {

    menuType = currMenuType;

    if (currMenuType === 'mobile') {

      const mobileMenu = document.getElementById('mainnav')

      mobileMenu.setAttribute('id', 'mainnav-mobi')

      mobileMenu.hidden = true;

      const hasChildMenu = document.getElementById('mainnav-mobi').querySelectorAll('li:has(ul)');

      const siteHead = document.getElementById('site-header-inner');

      siteHead.parentNode.insertAfter(mobileMenu, siteHead);

      hasChildMenu.forEach(li => li.querySelectorAll('ul').forEach(ul => ul.hidden = true));

      document.querySelectorAll('.btn-menu')

        .forEach(btnmenu => btnmenu.classList.remove('active'));

      hasChildMenu.forEach(li => li.querySelectorAll('a').forEach(a => {

        const span = document.createElement("span");

        span.classList.add("btn-submenu");

        a.parentNode.insertAfter(span, a);

      }));

    } else {

      const desktopMenu = document.getElementById('mainnav-mobi')

      desktopMenu.setAttribute('id', 'mainnav')

      desktopMenu.removeAttribute('style');

      desktopMenu.querySelectorAll('.submenu').forEach(sm => sm.removeAttribute('style'));

      document.getElementById('header').querySelectorAll('.nav-wrap').forEach(navwrap => {

        navwrap.appendChild(desktopMenu); // you need to clone here if more than one 

      });

      document.querySelectorAll('.btn-submenu').forEach(bsm => bsm.remove());

    }

  }

};


let responsiveMenu = function() {

  var menuType = 'desktop';


  window.addEventListener('load', load_resize)

  window.addEventListener('resize', load_resize)


  document.getElementById("container").addEventListener('click', function(e) { // a div container for mobile-button elements

    const tgt = e.target;

    if (tgt.classList.contains('mobile-button')) {

      document.getElementById('mainnav-mobi').classList.toggle("show") // slideToggle(300); needs a transition

      tgt.classList.toggle('active');

    }

  });


  document.getElementById("mainnav-mobi").addEventListener('click', function(e) {

    const tgt = e.target;

    if (tgt.classList.contains('btn-submenu')) {

      tgt.classList.toggle('active')

      tgt.nextElementSibling.slideToggle(300);

      e.stopImmediatePropagation()

    }

  });

};


查看完整回答
反對(duì) 回復(fù) 2023-07-14
?
呼喚遠(yuǎn)方

TA貢獻(xiàn)1856條經(jīng)驗(yàn) 獲得超11個(gè)贊

查詢(xún)

$(el).removeAttr('tabindex');

IE8+

el.removeAttribute('tabindex');


查看完整回答
反對(duì) 回復(fù) 2023-07-14
  • 2 回答
  • 0 關(guān)注
  • 190 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)