Are nested forms valid in HTML5?

后端 未结 2 1753
我在风中等你
我在风中等你 2020-12-18 19:17

Nested Forms Acceptable?

I can\'t find anything in the HTML5 doc that talks about nested forms. I\'m sure it\'s listed on some page, somewhere (perhaps a changelog

2条回答
  •  孤城傲影
    2020-12-18 19:50

    If they were supported then something like this would work:

    $('button').on('click', function(e) {
        var form = $(this).parents('form');
        e.preventDefault();
        if(!form) {
            form = $(this);
        }
        $('#output').val('from '+form.attr('id')+'\n'+form.serialize());
    });
    
    
    

    However because it is not officially supported you can look see the browser is preventing it (closing what it assumes are open-ended form elements). One alternative would be to have a single form but add data attributes to the individual inputs so JavaScript can collect the sub fields you want and manually build a POST from them.

提交回复
热议问题