Home Web Front-end JS Tutorial Solution to the problem that the submit event of the Form Form does not respond_Form special effects

Solution to the problem that the submit event of the Form Form does not respond_Form special effects

May 16, 2016 pm 06:59 PM
submit Not responding event

1. Problem description
By analogy, I used input.select() to test, but it was able to respond to the select event. Putting this reason aside for now, let’s see how to solve the current problem first.
Code example that does not respond to events:

[Ctrl A Select all Note: If you need to introduce external Js, you need to refresh to execute
]

In actual operation, there will be no alert comes out.
Although using the submit method to submit a form goes against the principles of Unobtrustive Javascript, it is sometimes necessary. For example, when making a search prompt (auto-complete) and selecting an Item, you need to use JS to submit the search form. 2. Problem Analysis

Since it does not respond to events, these events can only be triggered manually. Before determining the manual triggering plan, review the event registration method:
"Original" There are two ways to register, see the code example:

[Ctrl A Select all Note:
If you need to introduce external Js, you need to refresh it to execute
]

Such a registration event will Added a method onsubmit to the form. Therefore, you can directly execute this method, which is equivalent to manually triggering the event.
Look at the code example:
[Ctrl A Select All Note:
If you need to introduce external Js, you need to refresh to execute
]
This way you can get an alert.
But today’s “advanced” DOM2 standard registration method and IE’s registration method attachEvent are already very commonly used. For these registration methods, the onsubmit method does not exist. If you use form.onsubmit(), an error will be reported directly.

3. Solution


[Ctrl A Select all Note:
If you need to introduce external Js, you need to refresh to execute
]

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Event ID 4660: Object deleted [Fix] Event ID 4660: Object deleted [Fix] Jul 03, 2023 am 08:13 AM

Event ID 4660: Object deleted [Fix]

Get upcoming calendar events on your iPhone lock screen Get upcoming calendar events on your iPhone lock screen Dec 01, 2023 pm 02:21 PM

Get upcoming calendar events on your iPhone lock screen

In JavaScript, what is the purpose of the 'oninput' event? In JavaScript, what is the purpose of the 'oninput' event? Aug 26, 2023 pm 03:17 PM

In JavaScript, what is the purpose of the 'oninput' event?

How to implement calendar functions and event reminders in PHP projects? How to implement calendar functions and event reminders in PHP projects? Nov 02, 2023 pm 12:48 PM

How to implement calendar functions and event reminders in PHP projects?

How to implement change event binding of select elements in jQuery How to implement change event binding of select elements in jQuery Feb 23, 2024 pm 01:12 PM

How to implement change event binding of select elements in jQuery

Detailed explanation of input box binding events in Vue documents Detailed explanation of input box binding events in Vue documents Jun 21, 2023 am 08:12 AM

Detailed explanation of input box binding events in Vue documents

What are the commonly used events in jquery What are the commonly used events in jquery Jan 03, 2023 pm 06:13 PM

What are the commonly used events in jquery

A Deep Dive into Close Button Events in jQuery A Deep Dive into Close Button Events in jQuery Feb 24, 2024 pm 05:09 PM

A Deep Dive into Close Button Events in jQuery

See all articles