Js value of the difference between the form. All and not all

  • 2020-03-30 01:23:20
  • OfStack

In js, you can use form.xx. Value, or you can use form.all.xx. Value, so what's the difference between them?

I took it for granted that adding all is to take all of the xx in the form (if there are multiple elements with the same name) and return an array. Later, I searched the Internet and found that this is not the meaning.

All represents all the elements in the form, which means that form.all can access < Form> < / form> Tags contain arbitrary elements, including div, table, etc., while form.xx can only access form elements, such as input, select, etc.

The test is as follows:
<div id=div1><input name=text1 id=text1></div> 
<input name=text2 id=text2> 

Form.xx can only access text1 and text2 (common for form elements with names and ids), while form.all.xx can access text1, text2 and div1.

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 as form.all.xx(xx is id), or you can omit form.all, which means you can use xx directly.

Note: when accessing form elements, if there are multiple xx's, both form.xx and form.all.xx return arrays,

For non-form elements, if there are multiple elements with the same id, form.all.xx represents the first element and ignores the others.

Related articles: