简体   繁体   English

使用此脚本在博客上发布图片

[英]post image on a blog with this script

I have a webpage in PHP in which there is an image.我在 PHP 中有一个网页,其中有一张图片。 Post this image on a blog with this script.使用此脚本在博客上发布此图像。

    <div id="x"></div>
<script>
let div = document.getElementById("x");
let aTag = document.createElement("a");
aTag.href = 'http://www.meteoarachova.com/ws';
aTag.title = 'Εικόνα Κάμερας Μετεωρολογικού Σταθμού Αράχωβας';
aTag.target = '_blank';
aTag.outline = 'none';
let img = document.createElement("img");
img.src = "http://www.meteoarachova.com/webcam/arachova1.jpg";
img.style.width = '100%';
img.style.height = '80%';
aTag.append(img)
div.append(aTag);
console.log(document.getElementsByTagName('a')[0])
</script>

But I also want to post a second images at a different point on the same blog.但我也想在同一个博客的不同位置发布第二张图片。 The two images to be in completely different places on the page and not next to each other.这两个图像在页面上完全不同的位置,而不是彼此相邻。

I put the same code but it does not work.我输入了相同的代码,但它不起作用。

How can I customize it to work?如何自定义它以使其工作?

Id's are unique to the page, hence you can only have a single div with the id "x". Id 对页面来说是唯一的,因此您只能有一个 id 为“x”的 div。

That is why it probably won't work, or you're appending to the same place on the page.这就是为什么它可能不起作用,或者您要附加到页面上的同一位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM