我试图根据按下哪个提交按钮来触发两个单独的函数。当我单击“submit1”时,控制台日志中出现“openMailer_1”,但是当我单击“submit2”时,“openMailer_1”再次出现,而不是“openMailer_2”。知道我在这里做错了什么吗?
$('*[id^=submit]').live('click', function() {
var id = $(this).attr('id').slice(-1);
console.log(id);
$('#result_form').validate({
invalidHandler: function(form) {
//
},
submitHandler: function(form) {
openMailer['openMailer_' + id]();
}
});
});
var openMailer = {
openMailer_1: function() {
console.log('openMailer_1');
},
openMailer_2: function() {
console.log('openMailer_2');
}
}
<form id="result_form" action="" method="post">
<input type="submit" name="btn_send" id="submit1" value="submit1" />
<input type="submit" name="btn_send" id="submit2" value="submit2" />
</form>