基于ALT标签链接图像

时间:2016-08-18 01:34:16

标签: javascript wordpress getelementbyid

我有一个wordpress网站,我需要将图片链接到特定网址。

媒体上传器中通常的“链接到”功能不起作用,因此我想用Javascript实现这一点。

通常我会考虑做这样的事情:

Swarm initialized: current node (00ehj7mi2eaiix2uy46hn9ja8) is now a manager.

To add a worker to this swarm, run the following command:
    docker swarm join \
    --token SWMTKN-1-4tn8u9ywprdez0u2qfmv1lv0iq0x4r4aiwexgjg6gi7s63dqrw-192xx5jwhrxpy1q08xmb1dwyy \
    192.168.1.18:2377

To add a manager to this swarm, run the following command:
    docker swarm join \
    --token SWMTKN-1-4tn8u9ywprdez0u2qfmv1lv0iq0x4r4aiwexgjg6gi7s63dqrw-9ow8agcir34zovprrt512rbz3 \
    192.168.1.18:2377

但由于我无法使用getElementByID获取特定图片,我想知道是否有办法根据src或alt标签查找特定图片。

相关网页是: Rockaway Fest

1 个答案:

答案 0 :(得分:0)

试试这个例子。

<强> HTML

<style>
    img {display: none;}
    a {display: block;}
</style>
<img src="http://dummyimage.com/50x50/000000/ffffff.jpg&text=thisimage" alt="thisimage">
<img src="http://dummyimage.com/50x50/000000/ffffff.jpg&text=nothisimage" alt="nothis">

<a class="thisimage">This image</a>
<a class="thisimage">This image</a>
<a class="thisimage">This image</a>

<强> JS

<script src="https://code.jquery.com/jquery-1.12.4.min.js" type="text/javascript"></script>
<script type="text/javascript">
var image = document.querySelectorAll(" img[alt*='thisimage'] ");
//$('.thisimage').each(function (i, v) {
    $('.thisimage').append(image);
//});
</script>

<强>输出

<a class="thisimage">This image<img src="http://dummyimage.com/50x50/000000/ffffff.jpg&amp;text=thisimage" alt="thisimage"></a>
<a class="thisimage">This image<img src="http://dummyimage.com/50x50/000000/ffffff.jpg&amp;text=thisimage" alt="thisimage"></a>
<a class="thisimage">This image<img src="http://dummyimage.com/50x50/000000/ffffff.jpg&amp;text=thisimage" alt="thisimage"></a>