![](/img/trans.png)
[英]Adding link to a clickable HTML image with a link that will redirect to another webpage using JAVASCRIPT
[英]How to make an image as a clickable link to another html page using javascript?
这是我写的 JavaScript 代码:
var goToSecondPage= document.querySelector('.mobile');
goToSecondPage.addEventListener("click", function() {
document.location.href='productDetails.html';
})
我正在尝试在索引 html 页面(称为移动)上使用现有 class 中的图像,并将其作为可点击链接图像指向另一个名为productDetails.html
的文件
这取决于您的productDetails.html
文件所在的位置。 如果它在根目录中,请尝试
var goToSecondPage = document.querySelector('.mobile');
goToSecondPage.addEventListener("click", function() {
document.location.pathname = '/productDetails.html';
});
这只会改变你的路径,而不是整个 url。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.