【问题标题】:Data entry table, looking to add "New cell" button to generate a new row per each time clicked数据输入表,希望添加“新单元格”按钮以在每次单击时生成一个新行
【发布时间】:2017-08-31 17:20:48
【问题描述】:

<body>

  <div id="wrapper">
    <!-- Page Content -->
    <div id="page-content-wrapper">
      <div class="container-fluid">
        <div class="row">
          <div class="col-lg-12">

            <h1 align="center">Controls Page</h1>
            </br>
            <main>
              <section id="with-container-example">
                <!-- table -->
                <div class="container">
                  <div class="row">
                    <div class="table-responsive">

                      <!-- Table Titles -->
                      <table class="table table-hover">
                        <thead>
                          <tr class="alert-info">
                            <!-- <button type="button" class="btn" onclick="alert('All information saved!')">Save All</button><br></br> -->
                            <input type="button" class="btn" value="Save" style="float: right;" onclick="alert('All information saved!')"><br></br>
                            <th>TEXT:</th>
                            <th>~</th>
                            <th>~</th>
                            <th>DROPDOWN</th>
                            <th>DROPDOWN</th>
                            <th>TEXT:</th>
                            <th>TEXT:</th>
                            <th>TEXT:</th>
                            <th> ADD CELL(+)
                              </>
                          </tr>
                        </thead>

                        <!-- Tables -->
                        <tbody id="myTable">
                          <tr>
                            <td>A65.1</td>
                            <td>Table Cell</td>
                            <td>Control <br> Conflictin duties and area of responsibilities .......</td>
                            <td align="center">
                              <select id="selectbasic" name="selectbasic" class="selectpicker">
                                                        <option>-</option>
                                                        <option>Yes</option>
                                                        <option>No</option>
                                                    </select>
                            </td>
                            <td align="center">
                              <select id="selectbasic" name="selectbasic" class="selectpicker">
                                                        <option>-</option>
                                                        <option>Yes</option>
                                                        <option>No</option>
                                                        <option>Partially</option>
                                                    </select>
                            </td>
                            <td>Table cell</td>
                            <td>Table cell</td>
                            <td>Table cell</td>
                          </tr>
                          <tr>

                            <td>2</td>
                            <td>Table cell</td>
                            <td>Control <br><textarea rows="3" cols="60">Conflictin duties and area of responsibilities .......
                                                    </textarea></td>
                            <td align="center">
                              <select id="selectbasic" name="selectbasic" class="selectpicker">
                                                        <option>-</option>
                                                        <option>Yes</option>
                                                        <option>No</option>
                                                    </select>
                              <td align="center">
                                <select id="selectbasic" name="selectbasic" class="selectpicker">
                                                        <option>-</option>
                                                        <option>Yes</option>
                                                        <option>No</option>
                                                        <option>Partially</option>
                                                    </select>
                              </td>
                              <td>Table cell</td>
                              <td>Table cell</td>
                              <td>Table cell</td>
                          </tr>
                          <tr>

                            <td>3</td>
                            <td>Table cell</td>
                            <td>Table cell</td>
                            <td align="center">
                              <select id="selectbasic" name="selectbasic" class="selectpicker">
                                                        <option>-</option>
                                                        <option>Yes</option>
                                                        <option>No</option>
                                                    </select>
                              <td align="center">
                                <select id="selectbasic" name="selectbasic" class="selectpicker">
                                                        <option>-</option>
                                                        <option>Yes</option>
                                                        <option>No</option>
                                                        <option>Partially</option>
                                                    </select>
                              </td>
                              <td>Table cell</td>
                              <td>Table cell</td>
                              <td>Table cell</td>
                          </tr>
                          <tr>

Demo

我可以提供的完整开放代码将在代码笔链接中。

我设计这个项目的目的是在“文本字段”所在的位置添加文本框,然后在“新单元格”按钮所在的位置添加文本框,我希望在下面构建另一列。如果可能在文本框放置或添加爵士乐方面寻求帮助,请听取所有建议!

谢谢

【问题讨论】:

  • 修复缩进,可读性

标签: javascript jquery html css bootstrap-4


【解决方案1】:

我确实做到了这一点。一种方法是在单击某个元素后使用 jQuery append 一个新行。请看下面的代码:

jQuery(document).ready(function(){
    var i = 1;
    jQuery(".addRow").on('click', function(){
        i++; 
        jQuery('tbody').append('<tr><td><input type="file" name="'+i+'" id="attachment"></td></tr>');
    });
});

请注意,您需要将Class 或ID 放在将被单击以添加新行的元素上。

【讨论】:

  • 谢谢刘易斯,我将如何在你的括号内制定 .append('........') } );你的一个是添加一个文件,我想添加一个带有多个文本框和下拉列表的行。谢谢!
  • 文本框里会有值吗?还是由用户输入?
  • 由用户输入。因此,如果可能,TextBox、TextBox、TextBox、DropDown、DropDown、TextBox、TextBox、TextBox 将是布局
  • 用你的替换我的html,即&lt;tr&gt;&lt;td&gt;&lt;input type="file" name="'+i+'" id="attachment"&gt;&lt;/td&gt;&lt;/tr&gt;,它会起作用的。无论您在该追加中添加什么 html,都将追加到指定的元素。
  • 太棒了,我成功了!然后做一个remove按钮,会不会类似。 .像 jQuery('tbody').remove('...'); ?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-08-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-11-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多