用于表数据的循环

时间:2019-03-19 16:48:31

标签: javascript loops for-loop html-table

我需要用javascript循环填充表格中的数据。第一个表格数据应该只是数字1-24。这是我使用for循环的地方。

for(int i = 1; i < 13; i++) {

}

第二组表数据应为$ 150 + $ 299(值)的总和,通过for循环递增12次。第一个数字应该是$ 449,第二个数字应该是$ 449 + $ 299,依此类推,

我想要一个类似

的循环
for (int j = 1; j < 13; j += 299);
    value += j;
      j++; ( I don't know if this is correct)

这是我在DevExpress中的代码:

 @for (int i = 1; i < 13; i++)
 {
    <tr class="bundleRow">
       <td class="numbers">@i</td>
       <td class="totals"></td>
       <td class="numbers">@(i + 12)</td>
       <td class="totals"></td>
     </tr>
  }

这是完整的代码:

<div class="myleads-modals">

<!--Info Modal-->
                    <div class="col col-xs-7 col-xs-5 no-gutters border-left contentbox">
                        <div class="radio-stations">
                            <div class="customModalBtnContainer">
                                <button id="modalTrigger">Media Bundle</button>
                            </div>
                            <div id="customModalContainer" class="customModal">

                                <!-- Modal content -->
                                <div id="customModalContent">
                                    <span class="closeCustomModal">&times;</span>
                                    <div class="mediaBundleTitle">MEDIA TITLE</div>
                                 <table class="mediaBundle">
                                     <tr class-="bundleRow">
                                         <th class="numofSpotsTitle"># of Spots</th>
                                         <th class="raiTotalsTitle">RAI Total</th>
                                         <th class="numofSpotsTitle"># of Spots</th>
                                         <th class="raiTotalsTitle">RAI Total</th>
                                     </tr>
                                     @for (int i = 1; i < 13; i++)
                                     {
                                        <tr class="bundleRow">
                                            <td class="numbers">@i</td>
                                            <td class="totals"><span>$</span></td>
                                            <td class="numbers">@(i + 12)</td>
                                            <td class="totals"><span>$</span></td>
                                        </tr>
                                         }
                                 </table>
                                </div>
                            </div>
                            <script>
                                $(document).ready(function () {
                                    $("#modalTrigger").click(function () {
                                        $(".customModal").show();
                                    });
                                    $(".closeCustomModal").click(function () {
                                        $(".customModal").hide();
                                    });
                                });
                            </script>

1 个答案:

答案 0 :(得分:0)

使用公式(150 + i * 299)

@for (int i = 1; i < 13; i++){
     <tr class="bundleRow">
       <td class="numbers">@i</td>
       <td class="totals"><span>$</span></td>
       <td class="numbers">@(150+i*299)</td>
       <td class="totals"><span>$</span></td>
     </tr> }