RestructuredText - 将标题属性添加到链接

Ant*_*Roy 6 html restructuredtext python-sphinx

我试图在我的网站上使用从reStructuredText生成的jQuery lightBox实现.lightBox将图像周围的链接标题作为lightBox显示中图像的标题.

但是,我似乎无法在reStructuredText中找到一种在链接上提供title属性的方法 - 有没有人知道这样做的方法?我的图像定义如下:

.. image:: image001.thumb.jpg
    :alt: Some alt text here
    :target: image001.jpg
Run Code Online (Sandbox Code Playgroud)

所以我可以添加一个alt属性,但不能添加标题.可能的替代方案可能是使用目标作为参考,如下所示:

.. image:: image001.thumb.jpg
    :alt: Some alt text here
    :target: image1_

.. _image1: image001.jpg
Run Code Online (Sandbox Code Playgroud)

在后一种情况下,我不确定如何将属性添加到底部定义的链接(如果可能的话).

HBu*_*itz 0

我假设(尝试一下!),在 lightbox 初始化后,lightbox 不再需要 title 属性。因此,如果您想提供图像替代属性作为标题,那么如果您在灯箱初始化后调用它,则应该这样做:

function alt_2_title () {
    $("img[alt]").each(function(){
        $(this).attr('title', $(this).attr('alt'));
    });
});
Run Code Online (Sandbox Code Playgroud)

这会将每个具有 alt 属性的图像的 alt 复制到标题;如果您只想修改一些图像,您可以使用以下内容来限制图像选择:

function alt_2_title (name_of_container) {
    $("img[alt]", "#"+name_of_container).each(function(){
        $(this).attr('title', $(this).attr('alt'));
    });
});
Run Code Online (Sandbox Code Playgroud)

  • 除了 jQuery 和 lightbox 之外,我还想知道如何执行 OP 要求的操作。不将 alt 复制到标题,只是能够设置标题和 alt。 (3认同)