Submit HTML form on self page

后端 未结 5 1165
迷失自我
迷失自我 2020-12-13 02:08

I want an HTML form to submit to itself. How do I use the action attribute?

5条回答
  •  既然无缘
    2020-12-13 02:34

    You can leave action attribute blank. The form will automatically submit itself in the same page.

    
    

    According to the w3c specification, action attribute must be non-empty valid url in general. There is also an explanation for some situations in which the action attribute may be left empty.

    The action of an element is the value of the element’s formaction attribute, if the element is a Submit Button and has such an attribute, or the value of its form owner’s action attribute, if it has one, or else the empty string.

    So they both still valid and works:

    
    
    

    If you are sure your audience is using html5 browsers, you can even omit the action attribute:

    
    

提交回复
热议问题