我可以在title属性中放置一个链接吗?

时间:2022-02-22 09:45:01

I'm using the jQuery Fancybox plugin to create a modal window with the link's href as the content, and the title as its caption. I'd like to be able to have a clickable link in the caption (in this case to lead to a larger map) but I can't put an <a> tag into the title attribute. How might I go about putting this link in through Javascript, jQuery, or other methods?

我正在使用jQuery Fancybox插件创建一个模式窗口,链接的href作为内容,标题作为标题。我希望能够在标题中有一个可点击的链接(在这种情况下导致更大的地图)但我不能将标签放入title属性。我如何通过Javascript,jQuery或其他方法将此链接放入?

<a class='iframe' href='http://maps.google.com/maps?q=%235+Health+Department+Drive,+Troy,+MO+63379&amp;ll=38.979228,-90.97847&amp;z=13&amp;iwloc=near&amp;num=1&amp;output=embed' title='Google Map to Lincoln County Health Department'>Map to LCHD</a>

What it looks like http://i31.tinypic.com/i6frq1.png

看起来像什么http://i31.tinypic.com/i6frq1.png

4 个解决方案

#1


2  

I'm not familiar with this plugin, but this method comes to mind.

我不熟悉这个插件,但我想到了这个方法。

You can bury content elements within the anchor and modify you plugin to use the elements that your introduce. For example:

您可以在锚点中隐藏内容元素并修改插件以使用您引入的元素。例如:

<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>

Hope that helps.

希望有所帮助。

#2


0  

Maybe not the best suggestion but you can make your own atribute maybe something like this

也许不是最好的建议,但你可以制作自己的属性,也许是这样的

<a class='iframe' href='http://maps.google.com/maps?q=%235+Health+Department+Drive,+Troy,+MO+63379&amp;ll=38.979228,-90.97847&amp;z=13&amp;iwloc=near&amp;num=1&amp;output=embed' title='Google Map to Lincoln County Health Department' dest="/path/to/file.ext">Map to LCHD</a>

#3


0  

Keep the element => destination_link map as an object, and fetch values from it for redirection.

将element => destination_link map保留为对象,并从中获取值以进行重定向。

var linkmap = {
   lincoln:   '/location/3/',
   someplace: '/location/99'
}

Now you can use the values from linkmap in your click event (with [] or . operator)

现在,您可以在点击事件中使用linkmap中的值(使用[]或。运算符)

#4


0  

I passed additional data along with the :

我传递了额外的数据:

<a href="images/product.jpg" title="Product nummer 1" data-title-url="http://google.nl" rel="fancybox">

and used a custom callback for setting the title:

并使用自定义回调来设置标题:

{
    //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;
    },
}

http://fancybox.net/api

http://api.jquery.com/data/

#1


2  

I'm not familiar with this plugin, but this method comes to mind.

我不熟悉这个插件,但我想到了这个方法。

You can bury content elements within the anchor and modify you plugin to use the elements that your introduce. For example:

您可以在锚点中隐藏内容元素并修改插件以使用您引入的元素。例如:

<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>

Hope that helps.

希望有所帮助。

#2


0  

Maybe not the best suggestion but you can make your own atribute maybe something like this

也许不是最好的建议,但你可以制作自己的属性,也许是这样的

<a class='iframe' href='http://maps.google.com/maps?q=%235+Health+Department+Drive,+Troy,+MO+63379&amp;ll=38.979228,-90.97847&amp;z=13&amp;iwloc=near&amp;num=1&amp;output=embed' title='Google Map to Lincoln County Health Department' dest="/path/to/file.ext">Map to LCHD</a>

#3


0  

Keep the element => destination_link map as an object, and fetch values from it for redirection.

将element => destination_link map保留为对象,并从中获取值以进行重定向。

var linkmap = {
   lincoln:   '/location/3/',
   someplace: '/location/99'
}

Now you can use the values from linkmap in your click event (with [] or . operator)

现在,您可以在点击事件中使用linkmap中的值(使用[]或。运算符)

#4


0  

I passed additional data along with the :

我传递了额外的数据:

<a href="images/product.jpg" title="Product nummer 1" data-title-url="http://google.nl" rel="fancybox">

and used a custom callback for setting the title:

并使用自定义回调来设置标题:

{
    //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;
    },
}

http://fancybox.net/api

http://api.jquery.com/data/