扫码关注官方订阅号
我有一张图片,我想将其与网址链接。我用过javascript。 代码 after running the 代码 我想显示此图像,当我单击它时,我想打开其他一些页面,该页面已通过 url 链接到此图像。
我该怎么做?
我试过了,但没用。
代码(I took this from Stack Overflow)
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 Show me
我希望这个简单的代码片段能够帮助您。
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
扫描下载App
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
我希望这个简单的代码片段能够帮助您。