【问题标题】:how to change image link in "a" tag to <img>如何将 \"a\" 标签中的图片链接更改为 <img>
【发布时间】:2022-10-17 00:51:29
【问题描述】:

WordPress 插件之一将上传的图像呈现为链接:

&lt;a href="https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png" target="_blank" aria-label="new"&gt;news-paper.png&lt;/a&gt;

我想将其转换为带有 JavaScript 的标签,以便将链接显示为图像

【问题讨论】:

    标签: image hyperlink tags


    【解决方案1】:

    对 Wordpress 不太熟悉,因此可能有更简单的方法,但您可以通过...将该链接转换为图像

    • 将 <a ... 标签更改为 <image ... 标签:

    &lt;image src="https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png" target="_blank" aria-label="new"/&gt;
    • 根据该值通过 JS 添加图像

        function add_google_logo() {     show_image("https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png", 276,110, "Google Logo");
        }
    
    
        function show_image(src, width, height, alt) {
            var img = document.createElement("img");
            img.src = src;
            img.width = width;
            img.height = height;
            img.alt = alt;
            document.body.appendChild(img);
        }
    &lt;button onclick="add_google_logo();"&gt;Add Google Logo&lt;/button&gt;
    ^ 完全从这篇文章中删除:How to display image with JavaScript?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-24
      • 2015-06-14
      • 1970-01-01
      • 2020-08-16
      • 1970-01-01
      • 2014-11-27
      相关资源
      最近更新 更多