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

WBOY
Release: 2016-05-16 18:59:51
Original
1636 people have browsed it
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
]

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template