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.