![](/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.