两个输入提交,如何使用 jQuery 知道点击了哪一个
two input submits, how to know which one was clicked using jQuery
我有一个带有两个输入的 html 站点,我使用 jQuery 为每个按钮添加了一些功能。我怎么知道点击了哪一个?
$(function(){
$("#form1").submit(function(event){
if("clicked subit 1"){ //How to do this
alert("Submit1");
} else {
alert("Submit2");
}
});
});
<form name="form1" id="form1" method="post" action="#">
<input type="submit" value="Submit1" />
<input type="submit" value="Submit2"/>
</form>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script>
$(document).ready(function () {
$('input[type="submit"]').click(function (event) {
if ($(this).val() == "Submit1") {
alert("Submit1")
}
else {
alert("Submit2")
}
});
});
</script>
</head>
<body>
<form name="form1" id="form1" method="post" action="#">
<input type="submit" value="Submit1" />
<input type="submit" value="Submit2"/>
</form>
</body>
</html>
我有一个带有两个输入的 html 站点,我使用 jQuery 为每个按钮添加了一些功能。我怎么知道点击了哪一个?
$(function(){
$("#form1").submit(function(event){
if("clicked subit 1"){ //How to do this
alert("Submit1");
} else {
alert("Submit2");
}
});
});
<form name="form1" id="form1" method="post" action="#">
<input type="submit" value="Submit1" />
<input type="submit" value="Submit2"/>
</form>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script>
$(document).ready(function () {
$('input[type="submit"]').click(function (event) {
if ($(this).val() == "Submit1") {
alert("Submit1")
}
else {
alert("Submit2")
}
});
});
</script>
</head>
<body>
<form name="form1" id="form1" method="post" action="#">
<input type="submit" value="Submit1" />
<input type="submit" value="Submit2"/>
</form>
</body>
</html>