我不知道为什么表头位于表体。

huangapple go评论61阅读模式
英文:

i do not know why table head is located the table body

问题

在ejs文件中,表头覆盖了表体的问题如下所示:
我不知道为什么表头位于表体。

以下是相关代码:

<div class="container">
    <% for(var i = 0; i < user_show_cart.products.length; i++) { %>
    <td><%= i + 1 %></td>
    <form class="form" method="" action="" id="">
        <table class="table">
            <thead class="thead-dark">
                <tr>
                    <th>标题</th>
                    <th>图片</th>
                    <th>尺寸</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <input type="hidden" name="productId" value="<%= user_show_cart.products[i].productId %>"><!--不要放在td中以避免位移-->
                    <input type="text" name="productTitle" value="<%= user_show_cart.products[i].title %>">
                    <input type="text" name="productImg" value="<%= user_show_cart.products[i].img %>">
                    <input type="text" name="productSize" value="<%= user_show_cart.products[i].size %>">
                </tr>
            </tbody>
        </table>
        <table class="table">
            <thead class="thead-dark">
                <tr>
                    <th>颜色</th>
                    <th>价格</th>
                    <th>数量</th>
                    <th>小计价格</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <input type="text" name="productColor" value="<%= user_show_cart.products[i].color %>">
                    <input type="number" name="productPrice" value="<%= user_show_cart.products[i].price %>">
                    <input type="number" name="productQuantity" value="<%= user_show_cart.products[i].quantity %>" min="1" max="1000" step="1">
                    <input type="text" name="productSubTotalPrice" value="<%= user_show_cart.products[i].subTotalPrice %>">
                    <button type="submit" class="btn text-dark update">更改数量</button>
                </tr>
            </tbody>
        </table>
    </form>
    <% } %>
</div>

您尝试将表格分成两部分来解决此问题,但未成功。

英文:

table head coming over table body in ejs file like that
我不知道为什么表头位于表体。
the code is:

&lt;div class=&quot;container&quot;&gt;
            &lt;% for(var i = 0; i &lt; user_show_cart.products.length; i++) { %&gt;
            &lt;td&gt;&lt;%= i + 1 %&gt;&lt;/td&gt;
            &lt;form class=&quot;form&quot; method=&quot;&quot; action=&quot;&quot;  id=&quot;&quot;&gt;
                &lt;table class=&quot;table&quot;&gt;
                    &lt;thead class=&quot;thead-dark&quot;&gt;
                        &lt;tr&gt;                  
                            &lt;th&gt;Title&lt;/th&gt;
                            &lt;th&gt;Img&lt;/th&gt;
                            &lt;th&gt;Size&lt;/th&gt;
                        &lt;/tr&gt;
                    &lt;/thead&gt;
                    &lt;tbody&gt;
                        &lt;tr&gt;
                            &lt;input type=&quot;hidden&quot; name=&quot;productId&quot; value=&quot;&lt;%= user_show_cart.products[i].productId %&gt;&quot;&gt;&lt;!--do not put td not to make displacement--&gt;
                            &lt;input type=&quot;text&quot; name=&quot;productTitle&quot; value=&quot;&lt;%= user_show_cart.products[i].title %&gt;&quot;&gt;
                            &lt;input type=&quot;text&quot; name=&quot;productImg&quot; value=&quot;&lt;%= user_show_cart.products[i].img %&gt;&quot;&gt;
                            &lt;input type=&quot;text&quot; name=&quot;productSize&quot; value=&quot;&lt;%= user_show_cart.products[i].size %&gt;&quot;&gt;
                        &lt;/tr&gt;       
                    &lt;/tbody&gt;
                &lt;/table&gt;       
                &lt;table class=&quot;table&quot;&gt;
                    &lt;thead class=&quot;thead-dark&quot;&gt;
                        &lt;tr&gt;                  
                            &lt;th&gt;Color&lt;/th&gt;
                            &lt;th&gt;Price&lt;/th&gt;
                            &lt;th&gt;Quantity&lt;/th&gt;
                            &lt;th&gt;SubTotalPric&lt;/th&gt;
                        &lt;/tr&gt;
                    &lt;/thead&gt;
                    &lt;tbody&gt;
                        &lt;tr&gt;    
                            &lt;input type=&quot;text&quot; name=&quot;productColor&quot; value=&quot;&lt;%= user_show_cart.products[i].color %&gt;&quot;&gt;
                            &lt;input type=&quot;number&quot; name=&quot;productPrice&quot; value=&quot;&lt;%= user_show_cart.products[i].price %&gt;&quot;&gt;
                            &lt;input type=&quot;number&quot; name=&quot;productQuantity&quot; value=&quot;&lt;%= user_show_cart.products[i].quantity %&gt;&quot; min=&quot;1&quot; max=&quot;1000&quot; step=&quot;1&quot;&gt;&lt;/td&gt;
                            &lt;input type=&quot;text&quot; name=&quot;productSubTotalPrice&quot; value=&quot;&lt;%= user_show_cart.products[i].subTotalPrice %&gt;&quot;&gt;
                            &lt;button type=&quot;submit&quot; class=&quot;btn text-dark update&quot; &gt;Change Quantity&lt;/button&gt;
                        &lt;/tr&gt;
                    &lt;/tbody&gt;
                &lt;/table&gt;
            &lt;/form&gt;
            &lt;% } %&gt; 
        &lt;/div&gt;

i try to make the table with the normal case , where head over body
i tried to divide the table into 2 parts to overcome this problem, but not succeed.

答案1

得分: 1

以下是您要翻译的内容:

不包括必要的&lt;td&gt;元素的tbody行。

没有td的情况:

<table class="table">
<thead class="thead-dark">
<tr>
<th>Title</th>
<th>Img</th>
<th>Size</th>
</tr>
</thead>
<tbody>
<tr>
<input type="text" name="productTitle" value="Title">
<input type="text" name="productImg" value="Image">
<input type="text" name="productSize" value="Size">
</tr>
</tbody>
</table>

带有td的情况:

<table class="table">
<thead class="thead-dark">
<tr>
<th>Title</th>
<th>Img</th>
<th>Size</th>
</tr>
</thead>
<tbody>
<tr>
<td><input type="text" name="productTitle" value="Title"></td>
<td><input type="text" name="productImg" value="Image"></td>
<td><input type="text" name="productSize" value="Size"></td>
</tr>
</tbody>
</table>
英文:

The tbody rows do not include the necessary &lt;td&gt; elements.

Without the td's:

<!-- begin snippet: js hide: false console: false babel: false -->

<!-- language: lang-html -->

&lt;table class=&quot;table&quot;&gt;
&lt;thead class=&quot;thead-dark&quot;&gt;
&lt;tr&gt;                  
&lt;th&gt;Title&lt;/th&gt;
&lt;th&gt;Img&lt;/th&gt;
&lt;th&gt;Size&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;input type=&quot;text&quot; name=&quot;productTitle&quot; value=&quot;Title&quot;&gt;
&lt;input type=&quot;text&quot; name=&quot;productImg&quot; value=&quot;Image&quot;&gt;
&lt;input type=&quot;text&quot; name=&quot;productSize&quot; value=&quot;Size&quot;&gt;
&lt;/tr&gt;       
&lt;/tbody&gt;
&lt;/table&gt;

<!-- end snippet -->

With td's:

<!-- begin snippet: js hide: false console: false babel: false -->

<!-- language: lang-html -->

&lt;table class=&quot;table&quot;&gt;
&lt;thead class=&quot;thead-dark&quot;&gt;
&lt;tr&gt;                  
&lt;th&gt;Title&lt;/th&gt;
&lt;th&gt;Img&lt;/th&gt;
&lt;th&gt;Size&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;productTitle&quot; value=&quot;Title&quot;&gt;&lt;/td&gt;
&lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;productImg&quot; value=&quot;Image&quot;&gt;&lt;/td&gt;
&lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;productSize&quot; value=&quot;Size&quot;&gt;&lt;/td&gt;
&lt;/tr&gt;       
&lt;/tbody&gt;
&lt;/table&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年1月4日 06:06:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/74999121.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定