我正在使用 Wordpress 插件将 Facebook 事件加载到网页中。有一个大 anchor ,里面有一个事件 div。我想要在每个 fb-event div 的底部有一个小 anchor 。
我需要:
禁用第一个 anchor 而不删除它(删除它也会删除整个 div)。
在 fb-event div 底部创建一个新 anchor 。
将 href 从第一个 anchor 传递到第二个 anchor 。
我觉得我已经很接近了,但什么也没发生,这是我的代码,首先是 html,然后是 jQuery。提前致谢!
<div class='fb-event'>
<a class="fb-event-anchor" href="http://www.facebook.com/event.php?eid=1165884803462190" target="_blank">
<div class="fb-event-desc"><img src=https://scontent.xx.fbcdn.net/t31.0-8/s720x720/13920278_1335410149821833_1686522516711277604_o.jpg />
<div class='fb-event-title'>Spiritueel weekend - Een stapje verder</div>
<div class='fb-event-time'>10 september 2016 · 10:00 -<br>11 september 2016 · 17:00</div>
<div class='fb-event-location'>Balance in Life</div>
<div class='fb-event-description'>Lots
</div>
</div>
</a>
</div>
jQuery:
var fblink = $('.fb-event-anchor').attr('href');
$('.fb-event-anchor').click(function(){
return false; // prevents default action
});
$('.fb-event-description').append('<a class="fb-event-anchor-new" href="' . [fblink] . '"></a>');
最佳答案
尝试使用下面的代码
$(function () {
$('.fb-event-anchor').on("click", function (e) {
e.preventDefault();
});
var fblink = $('.fb-event-anchor').attr("href");
$( ".fb-event" ).append( '<a class="fb-event-anchor-new" href='+ fblink +'>NEW LINK</a>' );
});
关于php - jQuery:禁用 anchor 并使用相同的 href 创建一个新 anchor ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39249831/