简体   繁体   中英

Javascript Submit form with custom button?

Imagine an HTML form with multiple submit buttons, Im trying to write javascript function to submit this form with one specific button, usually we use:

form.submit();

but it doesnt specify which button is pressed,

any Ideas?

Using jQuery, you'd submit the form in an event handler that is bound to the click event on the desired button:

$('.trueSubmitFormButton').click(function(){
    form.submit();
});

Just fire it directly?

document.querySelector("#someButton").onclick();

Or if you're wanting to fire the submit button directly of a form, why not

document.querySelector("#someForm input[type='submit']").onclick();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM