Is it valid to have a html form inside another html form?

前端 未结 14 1977
故里飘歌
故里飘歌 2020-11-22 06:01

Is it valid html to have the following:

14条回答
  •  甜味超标
    2020-11-22 06:39

    A. It is not valid HTML nor XHTML

    In the official W3C XHTML specification, Section B. "Element Prohibitions", states that:

    "form must not contain other form elements."
    

    http://www.w3.org/TR/xhtml1/#prohibitions

    As for the older HTML 3.2 spec, the section on the FORMS element states that:

    "Every form must be enclosed within a FORM element. There can be several forms in a single document, but the FORM element can't be nested."

    B. The Workaround

    There are workarounds using JavaScript without needing to nest form tags.

    "How to create a nested form." (despite title this is not nested form tags, but a JavaScript workaround).

    Answers to this StackOverflow question

    Note: Although one can trick the W3C Validators to pass a page by manipulating the DOM via scripting, it's still not legal HTML. The problem with using such approaches is that the behavior of your code is now not guaranteed across browsers. (since it's not standard)

提交回复
热议问题