gpt4 book ai didi

javascript - href javascript 不适用于我的图像

转载 作者:行者123 更新时间:2023-12-03 03:19:58 25 4
gpt4 key购买 nike

我正在将存储在 firebase 中的图像从数据库添加到我的 html 页面中。这有效并且图像显示出来,但我无法使 href 属性在 img 元素上工作。我希望它可以点击。建议我在这里做错了什么?

var img = document.createElement("img");
img.src = snapshot.child("urlToImage " + (i) + " Content").val();
img.href = snapshot.child("urlToImage " + (i) + " Content").val();
img.height = 30;
img.width = 30;
contentA[i].appendChild(img);

最佳答案

可点击的图像

function clickMe(){
alert('Clicked!');
}
<!DOCTYPE html>
<html>
<body>
An image as a link:
<a onclick="clickMe()">
<img src="https://s3.eu-central-1.amazonaws.com/live-resource/productCategories/HF-AT/HF_PRINT_WEB_F781A5E7-1575-4D81-8317-BC51C8653EBB.jpeg" border="0" alt="W3Schools" src="logo_w3s.gif" width="100" height="100">
</a>

</body>
</html>

关于javascript - href javascript 不适用于我的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46613803/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com