The difference between form.all and not all in JS value _javascript skills

Source: Internet
Author: User
In JS to take value, can use Form.xx.value, also can use Form.all.xx.value, then what difference do they have?

The original thought that plus all is to take all xx in the form (if there are more than one name of the same element), returned an array, and then searched the Internet for a moment, found that not this meaning,

All represents all the elements in the form, that is, Form.all can access any element that the <form></form> tag contains, including Div, table, and so on, while form.xx can access only the form elements, such as input, Select, and so on.

The test is as follows:
Copy Code code as follows:

<form>
<div id=div1><input Name=text1 id=text1></div>
<input name=text2 id=text2>
</form>

FORM.XX can only access Text1, Text2 (common to form elements, name, and ID), while form.all.xx has access to Text1, Text2, Div1.

Generic for form elements, name and ID, such as above, Form.text1 and Form.all.text1 equals.

Non-form elements can only be accessed through form.all.xx (xx is ID) or omit Form.all, that is, you can use XX directly.

Note: When you access a FORM element, if you have more than one XX, both form.xx and form.all.xx return an array.

For non-form elements, if you have more than one element with the same ID, form.all.xx represents the first element and ignores the other.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.