Submitting a jQuery ajax form with two submit buttons

前端 未结 8 1049
花落未央
花落未央 2020-12-05 07:31

I have a form that looks like this:

8条回答
  •  悲&欢浪女
    2020-12-05 08:21

    I don't get how return false and preventDefault failed to do their job. Maybe try replacing the image buttons with linked images:

    
    
    $('#vote_form > a').click(function(e) {
        e.preventDefault();
    
        //one way to know which image was clicked
        alert($(this).attr('class'));
    
        $.post(...
    });
    

    You can always ensure that a form does not submit by binding to the submit event, e.g.:

    $('#vote_form').submit(function() {
        return false;
    });
    

提交回复
热议问题