時獲取正確的URL我試圖在使用Bootstrap image gallery時獲取模式彈出窗口中圖像的URL。由於圖片是動態加載的,因此我需要獲取該圖片的網址才能分享。有了這個代碼,我得到「未定義」作爲我的結果:使用jquery.prop()或.data()
$('#modal-gallery').on('load', function() {
var modalData = $(this).data('modal'),
// The current, associated link element:
linkElement = modalData.$links[modalData.options.index],
url = $(linkElement).prop('href');
$(".info").html("<a href='http://www.addthis.com/bookmark.php' class='addthis_button_compact' addthis:url='" + url + "'>" + "</a>");
//addthis code
addthis.toolbox('.info');
});
如果我用這個代碼,我得到一個href,但它的形式是「幻燈片/ image.jpg的」,而不是「HTTP:// WWW .example.com的/幻燈片/ image.jpg的」
$('#modal-gallery').on('load', function() {
var modalData = $(this).data('modal'),
// The current, associated link element:
linkElement = modalData.$links[modalData.options.index],
url = $(linkElement).data("href");
$(".info").html("<a href='http://www.addthis.com/bookmark.php' class='addthis_button_compact' addthis:url='" + url + "'>" + "</a>");
addthis.toolbox('.info');
});
你想鏈接的href或圖像的src?兩件不同的事情。 –
我需要鏈接到圖像src。 addthis需要添加鏈接addthis:url =「」。用我的第二個代碼塊,我得到結果_addthis:url =「slides/image.jpg」_當我需要_addthis:url ='http://www.example.com/slides/image.jpg'_ – Macsupport
對不起,這是代碼: 'addthis:url =「slides/image.jpg」'當我需要'addthis:url =「http://www.example.com/slides/image.jpg」' – Macsupport