在图像,类或ID上应用href

我是一名设计师。我需要将 中包含的相同 href 放在 中,或 中,或 包含在 中。class="kt-testimonial-title"id="slick-slide10"class="kt-testimonial-item-wrap kt-testimonial-item-0"class="kt-testimonial-image"


使用jquery或javascript可以吗?


部分:


<div class="kt-blocks-testimonial-carousel-item kb-slide-item slick-slide slick-current slick-active" style="width: 337px;" role="tabpanel" id="slick-slide10" aria-describedby="slick-slide-control10" data-slick-index="0" aria-hidden="false">

  <div class="kt-testimonial-item-wrap kt-testimonial-item-0" style="border-color:rgba(238, 238, 238, 1);padding-top:40px;padding-right:40px;padding-bottom:40px;padding-left:40px;max-width:500px">

<div class="kt-testimonial-text-wrap">

  <div class="kt-testimonial-media-wrap">

    <div class="kt-testimonial-media-inner-wrap" style="border-radius:px;border-width:0px 0px 0px 0px;padding:2px 2px 2px 2px">

      <div class="kadence-testimonial-image-intrisic" style="padding-bottom:100%">

        <div class="kt-testimonial-image" style="background-image:url(&quot;http://homeagent.devup.site/wp-content/uploads/2020/05/pegn.png&quot;);background-size:Contain"></div>

      </div>

    </div>

  </div>

  <div class="kt-testimonial-title-wrap">

    <h6 class="kt-testimonial-title">

      <a href="https://revistapegn.globo.com/Tecnologia/noticia/2020/04/coronavirus-de-ti-gestao-de-ponto-o-mercado-das-empresas-que-ajudam-no-home-office.html" target="_blank" aria-label=" (opens in a new tab)" rel="noreferrer noopener"

        class="ek-link" tabindex="0">De TI a gestão de ponto: o<br> mercado das empresas que<br> ajudam no home office</a>

    </h6>

  </div>

  <div class="kt-testimonial-content-wrap">

    <div class="kt-testimonial-content"></div>

  </div>

</div>

  </div>

</div>

源:

http://homeagent.devup.site/sobre/


萧十郎
浏览 82回答 2
2回答

幕布斯7119047

试试吧:// add common alias jquery&nbsp;$ = jQuery;const anchors = $('.kt-blocks-testimonial-carousel-item a.ek-link');$.each(anchors, function (i, e) {&nbsp; let anchor = $(e);&nbsp; let text = anchor.text();&nbsp; let textContainer = anchor.parent();&nbsp; let newAnchor = anchor.clone().empty();&nbsp; let carouselItem = anchor.parents('.kt-blocks-testimonial-carousel-item');&nbsp; carouselItem.wrap(newAnchor);&nbsp; textContainer.text(text);});这是一个不漂亮的代码,但在javascript控制台上 http://homeagent.devup.site/sobre/

德玛西亚99

这将工作:<div class="kt-blocks-testimonial-carousel-item kb-slide-item slick-slide slick-current slick-active" style="width: 337px;" role="tabpanel" id="slick-slide10" aria-describedby="slick-slide-control10" data-slick-index="0" aria-hidden="false"><div class="kt-testimonial-item-wrap kt-testimonial-item-0" style="border-color:rgba(238, 238, 238, 1);padding-top:40px;padding-right:40px;padding-bottom:40px;padding-left:40px;max-width:500px"><div class="kt-testimonial-text-wrap"><div class="kt-testimonial-media-wrap"><div class="kt-testimonial-media-inner-wrap" style="border-radius:px;border-width:0px 0px 0px 0px;padding:2px 2px 2px 2px"><div class="kadence-testimonial-image-intrisic" style="padding-bottom:100%"><div class="kt-testimonial-image" style="background-image:url(&quot;http://homeagent.devup.site/wp-content/uploads/2020/05/pegn.png&quot;);background-size:Contain"></div></div></div></div><div class="kt-testimonial-title-wrap"><h6 class="kt-testimonial-title"><a href="https://revistapegn.globo.com/Tecnologia/noticia/2020/04/coronavirus-de-ti-gestao-de-ponto-o-mercado-das-empresas-que-ajudam-no-home-office.html" target="_blank" aria-label=" (opens in a new tab)" rel="noreferrer noopener" class="ek-link" tabindex="0">De TI a gestão de ponto: o<br> mercado das empresas que<br> ajudam no home office</a></h6></div><div class="kt-testimonial-content-wrap"><div class="kt-testimonial-content"></div></div></div></div></div>&nbsp; &nbsp;&nbsp;<script>&nbsp; &nbsp; &nbsp; &nbsp; var slidesArr = document.querySelectorAll('.slick-slide');&nbsp; &nbsp; &nbsp; &nbsp; slidesArr.forEach(function(slide){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var a = document.createElement('a');&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; a.href = slide.querySelector('.kt-testimonial-title a').getAttribute('href');&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; a.appendChild(slide.querySelector('.kt-testimonial-item-wrap'));&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; slide.appendChild(a);&nbsp; &nbsp; &nbsp; &nbsp; });</script>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript