[英]How can add parameters to href url when click on tag a?
I want From home
page send parameter id
to carts
page: 我想从
home
发送参数id
到carts
页面:
This is current code, but it not woking: 这是当前代码,但无法正常运行:
<a href="carts" onclick="addParam();">detail</a>
<script>
function addParam()
{
var url = window.location.href;
var listId = localStorage.getItem('IDs', '');
url=url+ "?id=" +listId;
window.location.href = url;
}
</script>
How can add parameters to href url when click on tag a? 单击标签a时如何向href URL添加参数?
Either just override it by grabbing the element's (here done by passing this
to the function) href
要么只是通过抓住元素(在这里通过传递完成覆盖它
this
该功能) href
<a href="carts" onclick="addParam(this);">detail</a>
<script>
function addParam(el)
{
var listId = localStorage.getItem('IDs', '');
window.location.href = el.href + "?id=" +listId;
}
</script>
Or append it to the element's href
或将其附加到元素的
href
<a href="carts" onclick="addParam(this);">detail</a>
<script>
function addParam(el)
{
var listId = localStorage.getItem('IDs', '');
el.href += "?id=" +listId;
}
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.