如何使用Javascript将图像与URL链接起来?
P粉652495194
P粉652495194 2024-04-03 10:34:22
0
1
321

我有一张图片,我想将其与网址链接。我用过javascript。 代码 after running the 代码 我想显示此图像,当我单击它时,我想打开其他一些页面,该页面已通过 url 链接到此图像。

我该怎么做?

我试过了,但没用。

代码(I took this from Stack Overflow)

P粉652495194
P粉652495194

全部回复(1)
P粉638343995

function handleClick(){
 const image = new Image ()

image.src = "https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png"
image.style.width="200px"
image.style.height="200px"
image.alt="Google logo"
image.addEventListener("click", function() {
  window.location.href="https://www.google.com"
})

const element = document.getElementById('image-container')
if(element){
   element.appendChild(image)
}

}

Image will show here

我希望这个简单的代码片段能够帮助您。

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!