Introduction to the difference between form. all and without all in js values _ javascript skills

Source: Internet
Author: User
In js, you can use form. xx. value or form. all. xx. value. What is the difference between form. all and no all in js values? The following describes the values in js in detail. You can use form. xx. value or form. all. xx. value. What are their differences?

I used to assume that adding all is to get all xx in form (if there are multiple elements with the same name), the returned array is returned. Then I searched the internet and found that this is not the meaning,

All indicates all elements in form, that is, form. all can access any element contained in the tag, including p and table, while form. xx can only access form elements, such as input and select.

The test is as follows:

The Code is as follows:




Form. xx can only access text1 and text2 (for form elements, name and id), while form. all. xx can access text1, text2, and p1.

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

For non-form elements, you can only access them in form. all. xx (xx is id). You can also omit form. all, that is, you can directly use xx.

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

For non-form elements, if multiple elements with the same id exist, form. all. xx indicates the first element, and other elements are ignored.
Related Article

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.