[英]How to change the parameter value of href function in javascript
有一个具有2个参数的功能工具。 我必须更改参数a(1到2)和b(2到3)的值。 我该如何更改? 请给您宝贵的答案。
<html>
<head>
<script>
function tool(a,b) {
}
</script> </head>
<body>
<a href="javascript:tool(1,2)" name ="link" title="before click">click here</a>
</body>
</html>
您可以更新锚节点的href
属性。
function tool(a, b) { console.log(a, b); } document.getElementById('link').href='javascript:tool(2, 3);';
<a href="javascript:tool(1, 2)" id="link" title="before click">click here</a>
使用您想做的事。 但是您的问题尚不清楚。 据我了解,我正在回答您
答案1
function tool(a, b) { console.log(a, b); document.getElementById('link').href='javascript:tool(2, 3);'; }
<a href="javascript:tool(1, 2)" id="link" title="before click">click here</a>
答案2
function tool(a, b) { console.log(a, b); document.getElementById('link').href='javascript:tool('+(Number(a)+1)+', '+(Number(b)+1)+');'; }
<a href="javascript:tool(1, 2)" id="link" title="before click">click here</a>
您可以添加事件监听器:
function tool(a, b) { console.log(a, b); } document.getElementById("link").addEventListener('click', function(e) { e.preventDefault(); tool(2, 3); });
<a href="javascript:tool(1,2)" name="link" id="link" title="before click">click here</a>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.