[英]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.