There is a function tool which have 2 parameters. I have to change the value of the parameter a(1 to 2) and b(2 to 3). How can I change this? Please give your valuable answer.
<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>
You could update the href
property of the anchor node.
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>
Use what you want to do. But your question is not clear. As I understand I am giving your answer
Answer 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>
Answer 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>
You can add an event listener:
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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.