猿问

从表中动态创建的输入中获取值

我有一张桌子


   <form id="project-form">

                    <table id="project-table" class="table table-striped table-inverse table-responsive">

                        <caption>Projects</caption>

                        <thead class="thead-inverse">

                            <tr>

                                <th scope="col">#</th>

                                <th scope="col">Project name</th>

                                <th scope="col">Description</th>

                                <th scope="col">Estimated time (min)</th>

                                <th scope="col">Actual time (min)</th>

                                <th scope="col">Add task</th>

                                <th scope="col">Delete project</th>

                            </tr>

                        </thead>

                        <tbody id="project-body">



                        </tbody>

                    </table>

                </form>

此表填充了来自 AJAX GET 请求的数据


function getProjects() {

  $.ajax({

    method: 'GET',

    dataType: 'json',

    data: {

      functionToCall: 'project',

    },

    url: 'http://localhost/WBS/php/api/requests/get.php',

    success: (response) => {

      $.each(response, function () {

        $.each(this, function (index, value) {

          $('#project-body').append(

            `

            <tr>

                <td>

                  <input class="form-control" type="hidden" name="projectid" id="projectid"  value="${value.projectid}">

                </td>

                <td>

                  <input class="form-control" type="text" name="projectName" id="projectName" value="${value.title}">

                </td>

                <td>

                  <input class="form-control" type="text" name="description" id="description"  value="${value.description}">

                </td>

慕森卡
浏览 76回答 1
1回答

慕村225694

我认为您可以重命名您的输入,例如:&nbsp;name="projectid[]"然后 PHP 将收到这些值的数组:$total = count($_POST["projectid"]);for ($i = 0; $i < $total; $i++) {&nbsp; &nbsp; $title = $_POST["projectName"][$i];&nbsp; &nbsp; $description = $_POST["description"][$i];&nbsp; &nbsp; $estimatedTime = $_POST["estimatedTime"][$i];&nbsp; &nbsp; $actualTime = $_POST["actualTime"][$i];&nbsp; &nbsp; // Your INSERT query is performed here}
随时随地看视频慕课网APP
我要回答