2 回答
TA贡献1794条经验 获得超8个赞
试试吧:
// add common alias jquery
$ = jQuery;
const anchors = $('.kt-blocks-testimonial-carousel-item a.ek-link');
$.each(anchors, function (i, e) {
let anchor = $(e);
let text = anchor.text();
let textContainer = anchor.parent();
let newAnchor = anchor.clone().empty();
let carouselItem = anchor.parents('.kt-blocks-testimonial-carousel-item');
carouselItem.wrap(newAnchor);
textContainer.text(text);
});
这是一个不漂亮的代码,但在javascript控制台上 http://homeagent.devup.site/sobre/
TA贡献1770条经验 获得超3个赞
这将工作:
<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("http://homeagent.devup.site/wp-content/uploads/2020/05/pegn.png");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>
<script>
var slidesArr = document.querySelectorAll('.slick-slide');
slidesArr.forEach(function(slide){
var a = document.createElement('a');
a.href = slide.querySelector('.kt-testimonial-title a').getAttribute('href');
a.appendChild(slide.querySelector('.kt-testimonial-item-wrap'));
slide.appendChild(a);
});
</script>
添加回答
举报