我正在使用jQuery Fancybox plugin创建一个模态窗口,链接的href
作为内容,title
作为其标题。我希望能够在标题中有一个可点击的链接(在这种情况下导致更大的地图),但我不能将<a>
标记放入title
属性。我如何通过Javascript,jQuery或其他方法将此链接放入?
<a class='iframe' href='http://maps.google.com/maps?q=%235+Health+Department+Drive,+Troy,+MO+63379&ll=38.979228,-90.97847&z=13&iwloc=near&num=1&output=embed' title='Google Map to Lincoln County Health Department'>Map to LCHD</a>
我不熟悉这个插件,但是我想到了这个方法。
您可以在锚点中隐藏内容元素并修改插件以使用您引入的元素。例如:
<a class='iframe'
href='http://maps.google.com/blahlblahlbah'
title='Google Map to Lincoln County Health Department'>Map to LCHD
<span class="title-href" style="display: none">http://zebrakick.com</span>
</a>
希望有所帮助。
也许不是最好的建议,但你可以使自己的属性可能是这样的
<a class='iframe' href='http://maps.google.com/maps?q=%235+Health+Department+Drive,+Troy,+MO+63379&ll=38.979228,-90.97847&z=13&iwloc=near&num=1&output=embed' title='Google Map to Lincoln County Health Department' dest="/path/to/file.ext">Map to LCHD</a>
将element => destination_link映射保留为对象,并从中获取值以进行重定向。
var linkmap = {
lincoln: '/location/3/',
someplace: '/location/99'
}
现在,您可以在点击事件中使用linkmap中的值(使用[]或。运算符)
我传递了附加数据:
<a href="images/product.jpg" title="Product nummer 1" data-title-url="http://google.nl" rel="fancybox">
并使用自定义回调来设置标题:
{
//fancybox options array
titleFormat: function(title, currentArray, currentIndex, currentOpts){
var currentElement = currentArray[currentIndex];
var html = "<h1>" + title + "</h1>";
var titleUrl = $(currentElement).data("title-url");
if (titleUrl) {
var link = $("<a>", {href: titleUrl, text: titleUrl, target: "_blank"});
html += " (" + link.prop("outerHTML") + ")";
}
return html;
},
}