1

If I have 2 submit buttons on a form:

<input name="submit" type="submit" value="Button 1">
<input name="submit" type="submit" value="Button 2">

I have this jquery but every time I click button 2 I get the alert for button 1.

$('form.profile').submit(function() {
if ($("input[type=submit]").val() == 'Button 1')
{
alert('you clicked button 1');
return false;
}
elseif ($("input[type=submit]").val() == 'Button 2')
{
alert('you clicked button 2');
return false;
}
});

I need to perform form validation before the form is sent to the server and I need to be able to determine which of the 2 buttons was clicked.

Is it possible to identify which of the 2 buttons caused the form to be submitted using jquery?

4

1 回答 1

0

这有帮助吗!!! http://jsfiddle.net/hun4U/

您可以使用点击事件代替 formSubmission。

HTML:-

<input name="submit" id="submit1" type="submit" value="Button 1">
<input name="submit" id="submit2" type="submit" value="Button 2">

脚本

$('#submit1').click(function(){
//do your actions here
});

$('#submit2').click(function(){
    //do your actions here
    });
于 2013-03-21T02:47:10.967 回答