Home  >  Article  >  Web Front-end  >  Introduction to the difference between form.all and not adding all in js value_javascript skills

Introduction to the difference between form.all and not adding all in js value_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:03:061297browse

To get the value in js, you can use form.xx.value or form.all.xx.value. So what is the difference between them?

I originally thought that adding all means getting all xx in the form (if there are multiple elements with the same name), and returning an array. Later, I searched on the Internet and found that this is not the meaning.

all represents all elements in the form, which means that form.all can access any element contained in the

tag, including div, table, etc., while form.xx can only access form elements. , like input, select, etc.

The test is as follows:

Copy code The code is as follows:





form.xx can only access text1 and text2 (common to form elements, name and id), while form.all.xx can access text1, text2, and div1.

For form elements, name and id are common. For example, above, form.text1 and form.all.text1 are equivalent.

Non-form elements can only be accessed through form.all.xx (xx is the id). You can also omit form.all, which means you can use xx directly.

Note: When accessing form elements, if there are multiple xx, form.xx and form.all.xx will return arrays.

For non-form elements, if there are multiple If there are two elements with the same ID, form.all.xx represents the first element and the others will be ignored.
Statement:
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