What's the point of HTML forms `name` attribute?

后端 未结 6 1806
情歌与酒
情歌与酒 2020-12-05 09:01

What\'s the point of the name attribute on an HTML form? As far as I can tell, you can\'t read the form name on submission or do anything else with it. Does it

6条回答
  •  生来不讨喜
    2020-12-05 09:39

    Once you assign a name to an element, you can refer to that element via document.name_of_element throughout your code. Doesn't work too tell when you've got multiple fields of the same name, but it does allow shortcuts like:

    document.myform.submit();

    instead of

    document.getElementsByName('myform')[0].submit();
    

提交回复
热议问题