Submit form using a button outside the <form> tag

前端 未结 13 1491
南旧
南旧 2020-11-22 09:45

Say I have:

13条回答
  •  旧巷少年郎
    2020-11-22 10:08

    Update: In modern browsers you can use the form attribute to do this.


    As far as I know, you cannot do this without javascript.

    Here's what the spec says

    The elements used to create controls generally appear inside a FORM element, but may also appear outside of a FORM element declaration when they are used to build user interfaces. This is discussed in the section on intrinsic events. Note that controls outside a form cannot be successful controls.

    That's my bold

    A submit button is considered a control.

    http://www.w3.org/TR/html4/interact/forms.html#h-17.2.1

    From the comments

    I have a multi tabbed settings area with a button to update all, due to the design of it the button would be outside of the form.

    Why not place the input inside the form, but use CSS to position it elsewhere on the page?

提交回复
热议问题