表单标签不会将元素包含在表格内 [英] Form tag won't enclose elements inside a table

查看:29
本文介绍了表单标签不会将元素包含在表格内的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个奇怪的问题;我在 <tr> 中有一个表单,但是该表单拒绝在其中包装任何标签.我制作了一个快速的 JSFiddle 这是无效的,所以我的问题是我可以创建一个包含两个或多个 tr 和任意数量的其他元素的表格吗? 表格有其他行它与表单无关,因此将 <form> 放在整个表中是没有帮助的,尽管看到其他行不会有表单的任何输入(POST 请求),我假设一个 form 可以放在整个桌子周围.

哪个是更好的解决方案;全表换行,还是仅将所需行包含在 form 标记中的有效修复?我知道我可以将 table 放在 td > 中.表单,但是嵌套表中的列宽不会相同,这就是我来问这个问题的原因.

解决方案

结构中除了
>.你的表单标签需要封装在两个 或者你的整个 需要放在
中> 标签.

<tr><td><表格>...表格数据...</表单></td></tr>

...或...

<表格>...
</表单>

I've run into a curious problem; I've got a form inside a <tr>, however the form refuses to wrap any tags inside it. I've made a quick JSFiddle here to play around with. Firebug reports that the form isn't wrapping anything:

The <form> element is greyed out and not wrapping anything. The HTML for this test is below

<table>
    <form>
        <tr>
            <td>Input</td>
            <td>Another input</td>
        </tr>
        <tr>
            <td colspan="4"><span>Other stuff</span></td>
        </tr>
    </form>

    <tr>
        <td>
            Rows not affected by the form
        </td>
    </tr>
    <tr>
        <td>
            Rows not affected by the form
        </td>
    </tr>
</table>

As can be seen, the form holds two trs in the written markup. I read here that this is invalid, so my question is can I create a form that holds two or more trs and an arbitrary amount of other elements inside a table? The table has other rows in it not associated with the form, so putting a <form> round the entire table is unhelpful, although seeing as the other rows won't have any inputs for the form (POST request), I suppose a form could be put around the entire table.

Which is a better solution; whole-table wrap, or a working fix for just enclosing the needed rows in a form tag? I know I could put a table inside a td > form, but then the column widths wouldn't be the same in the nested table, which is why I came to ask this question.

解决方案

You cannot interrupt the <table> structure with any tags besides <thead>, <tfoot>, <tbody>, <tr>, <th>, or <td>. You form tags need to be encapsulated between two <td> or your entire <table> needs to be placed within the <form> tag.

<table>
    <tr>
        <td>
            <form>
            ...form data...
            </form>
        </td>
    </tr>
</table>

..or..

<form>
    <table>
    ...
    </table>
</form>

这篇关于表单标签不会将元素包含在表格内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆