[英]form action to direct to a new html page is not working
I have a product search result page (html1 file), i want to be able to click on any of the product and then be directed to product detail page (Product_overview.html). 我有一个产品搜索结果页面(html1文件),我希望能够单击任何一种产品,然后定向到产品详细信息页面(Product_overview.html)。
the product result are generated by this firebase code 产品结果由此firebase代码生成
var itemdetailref = Cataloguedatabase.ref('/Listings/');
return itemdetailref.once('value').then(function(snapshot){
snapshot.forEach(childSnapshot => {
let key = childSnapshot.key;
//use ES6 includes function
if(key.includes(searchcontent)){
var searchresults = childSnapshot.val();
var container = document.getElementById("searchcontainer");
var productcard = `
<div action='../html/Product_overview.html' class="product" id="${key}" method='GET' onclick="showdetail(this);" name="product-view" role="search">
<div class="img-container">
<img src=${searchresults.ProductImageUrl}>
</div>
<div class="product-info">
<div class="product-content">
<span class="button" id="price">${searchresults.Price}</span>
</div>
</div>
</div>`
container.innerHTML += productcard;
} else {
console.log("No match was found");
}
});
})
and then the function to check for local storage 然后是检查本地存储的功能
function showdetail(element){
var productID = element.id;
alert(productID);
var currentUrl = window.location.href;
url = currentUrl + encodeURIComponent(productID);
document.location.href = url;
}
when I click of the product div it does not redirect the page to Product_overview.html in the div action. 当我单击产品div时,它不会在div操作中将页面重定向到Product_overview.html。 I tried changing the div to form too nothing changes. 我试图将div更改为没有任何变化的形式。 What am I doing wrongly and how can I fix this? 我做错了什么,该如何解决?
The action attribute only works for the form element. action属性仅适用于form元素。 You can either nest a form inside your div, or an anchor tag pointing to the desired url. 您可以将表格嵌套在div内,也可以将锚标记指向所需的网址。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.