Determining the Default Submit Button in HTML Forms
When submitting an HTML form without clicking a specific submit button, such as by pressing Enter or using HTMLFormElement.submit() in JavaScript, browsers need to determine which of multiple submit buttons (if any) should be treated as the one pressed. This determination has implications for triggering onclick event handlers and the data sent to the web server.
Browser Behavior
Experiments have shown that:
When pressing Enter:
When using HTMLFormElement.submit():
Standards Specification
The HTML standard does not explicitly specify the behavior for submitting a form without a specific button. It only requires that the form be submitted when a submit button is activated.
Recommended Approach
Given the lack of a clear standard and the variance in browser behavior, it is recommended to avoid relying on a specific default submit button when designing HTML forms. Instead, clearly indicate which submit button should be used in any given scenario.
अस्वीकरण: उपलब्ध कराए गए सभी संसाधन आंशिक रूप से इंटरनेट से हैं। यदि आपके कॉपीराइट या अन्य अधिकारों और हितों का कोई उल्लंघन होता है, तो कृपया विस्तृत कारण बताएं और कॉपीराइट या अधिकारों और हितों का प्रमाण प्रदान करें और फिर इसे ईमेल पर भेजें: [email protected] हम इसे आपके लिए यथाशीघ्र संभालेंगे।
Copyright© 2022 湘ICP备2022001581号-3