試試這個例子。
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>
OUTPUT
<a class="thisimage">This image<img src="http://dummyimage.com/50x50/000000/ffffff.jpg&text=thisimage" alt="thisimage"></a>
<a class="thisimage">This image<img src="http://dummyimage.com/50x50/000000/ffffff.jpg&text=thisimage" alt="thisimage"></a>
<a class="thisimage">This image<img src="http://dummyimage.com/50x50/000000/ffffff.jpg&text=thisimage" alt="thisimage"></a>
'document.querySelectorAll( 「IMG [ALT * = '野餐']」) ' – dandavis
鏈接到什麼?爲什麼不使用alt標籤在PHP/Wordpress循環中建立鏈接?我需要更多信息 –