twitter-bootstrap 表格内的表格或表格内的表格,哪一个适合有效的 Twitter Bootstrap 标记?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27772829/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 22:05:03  来源:igfitidea点击:

Form inside table or table inside form, which one is the right for valid Twitter Bootstrap markup?

htmltwitter-bootstrap

提问by ReynierPM

I'm working on a template based on Twitter Bootstrap and I have a doubt as title says: Form inside table or table inside form, which one is the right for valid Twitter Bootstrap markup? Are both valid?

我正在开发一个基于 Twitter Bootstrap 的模板,我有一个疑问,正如标题所说:表格内的表格或表格内的表格,哪个适合有效的 Twitter Bootstrap 标记?两者都有效吗?

First markup:

第一个标记:

<form id="fabForm" method="post">
    <div class="form-group">
        <div class="table-responsive">
            <table class="table table-condensed">
                <thead>
                    <tr>
                        <th></th>
                        <th>Col Title</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td>
                            <div class="checkbox">
                                <label>
                                    <input type="checkbox" name="fabLinkChoice[]" value="1">
                                </label>
                            </div>
                        </td>
                        <td>Dist1</td>                           
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
    <div>
        <button type="submit" class="btn btn-primary" disabled="" id="btnAgregarSelFabricante"><i class="fa fa-save"></i> Add</button>
    </div>
</form>

Second markup:

第二个标记:

        <div class="table-responsive">
            <table class="table table-condensed">
                <thead>
                    <tr>
                        <th></th>
                        <th>Col Title</th>
                    </tr>
                </thead>
                <tbody>
                     <form id="fabForm" method="post">
                         <div class="form-group">
                             <tr>
                                  <td>
                                      <div class="checkbox">
                                           <label>
                                               <input type="checkbox" name="fabLinkChoice[]" value="1">
                                           </label>
                                     </div>
                                 </td>
                                 <td>Dist1</td>                           
                             </tr>
                             <tr>
                                 <td colspan="2">
                                     <button type="submit" class="btn btn-primary" disabled="" id="btnAgregarSelFabricante"><i class="fa fa-save"></i> Add</button> 
                                 </td>
                             </tr>
                        </div>
                    </form>
               </tbody>
            </table>
        </div>
    </div>
<div>

NOTE:my doubt has a origin on this code. There you'll notice the code of the first example and also it's on a Bootstrap Modal, but I can't get it look fine. This is what I see on Chrome:

注意:我的怀疑源于此代码。在那里您会注意到第一个示例的代码,并且它位于 Bootstrap Modal 上,但我无法让它看起来很好。这是我在 Chrome 上看到的:

enter image description here

在此处输入图片说明

And I don't know if I'm missing something in my markup. Around why I'm using tables is because is a tabular data and I think this is the right or I'm wrong?

而且我不知道我的标记中是否遗漏了什么。我使用表格的原因是因为它是表格数据,我认为这是对的还是错的?

回答by Michael Petito

The permitted contents of a tbodytagare zero or more trtags, so your second example is not valid HTML.

标签允许内容tbody是零个或多个tr标签,因此您的第二个示例不是有效的 HTML。

You could move your form inside a table cell, but more commonly you will see a table inside a form instead of vice versa.

您可以在表格单元格内移动表格,但更常见的是,您会在表格内看到表格,反之亦然。

It also appears from your limited examples that you may be using a table for layout purposes, which I would urge you to reconsider.

从您的有限示例中还可以看出,您可能将表格用于布局目的,我敦促您重新考虑。