jQuery 将值传递给 javascript onClick()
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15356257/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Passing values to javascript onClick()
提问by user2043210
I have a website with some links. when a user clicks on each link it should pass different integer values which I can use in a .js file. I have to make some operations on the basis of these integer values. please help!!!
我有一个带有一些链接的网站。当用户单击每个链接时,它应该传递不同的整数值,我可以在 .js 文件中使用这些值。我必须根据这些整数值进行一些操作。请帮忙!!!
回答by bipen
Though this question is most likely to get closed. You can call a function and pass the integer as parameter.
虽然这个问题最有可能被关闭。您可以调用函数并将整数作为参数传递。
try this
尝试这个
<a href="#" onclick="yourFunction('1')">click1</a>
<a href="#" onclick="yourFunction('2')">click2</a>
javascript
javascript
function yourFunction(intValue){
alert(intValue);
}
回答by Chiranjeevi
<!DOCTYPE html>
<html>
<head>
<title>Functions</title>
</head>
<body>
<script type="text/javascript">
function add(firstnum,secondnum) {
document.write(firstnum+secondnum);
}
</script>
<h1>onclick Function called</h1>
<input type="button" value="Sum Me" onclick="add(2,3)" />
</body>
</html>
Output:
输出:
5
5