简体   繁体   中英

Most supported method to get submit button value

What is the most supported way to get a name and value to post from the button which was used to submit a form (particularly if there are multiple)?

From what I'm reading, SubmitEvent.submitter seems to be the most common way. But there seems to be some gaps in older browser support. Anyone have a fallback way to ensure better supportability of something like this?

Simple example below:

 <script> function showSender(e) { console.log("submit element: ", e.submitter); console.log("submit element value: ", e.submitter.innerHTML); return false; // <- break sending form } </script> Form: <form onsubmit='return showSender(event);' method='post' action='#'> Value: <input type='text' value='x'> <button type='submit'>ABC</button> <button type='submit'>XYZ</button> </form>

Back compatibility: https://caniuse.com/mdn-api_submitevent_submitter

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