Jquery submit form [duplicate]

2019-01-10 23:00发布

问题:

This question already has an answer here:

  • Submit a form using jQuery 22 answers

How can I submit a specific form using the follow code (example the id of my form is #form1).

$(".nextbutton").click(function() { submit; });

回答1:

Try this lets say your form id is formID

$(".nextbutton").click(function() { $("form#formID").submit(); });


回答2:

You can try like:

   $("#myformid").submit(function(){
        //perform anythng
   });

Or even you can try like

$(".nextbutton").click(function() { 
    $('#form1').submit();
});


回答3:

Since a jQuery object inherits from an array, and this array contains the selected DOM elements. Saying you're using an id and so the element should be unique within the DOM, you could perform a direct call to submit by doing :

$(".nextbutton").click(function() { 
  $("#formID")[0].submit();
});


回答4:

You don't really need to do it all in jQuery to do that smoothly. Do it like this:

$(".nextbutton").click(function() { 
   document.forms["form1"].submit();
});


回答5:

If you have only 1 form in you page, use this. You do not need to know id or name of the form. I just used this code - working:

document.forms[0].submit();


回答6:

Use the following jquery to submit a selectbox with out a submit button. Use "change" instead of click as shown above.

$("selectbox").change(function() { 
   document.forms["form"].submit();
});

Cheers!



回答7:

Try this :

$('#form1').submit();

or

document.form1.submit();