1

我有一个包含数据表和弹出警报的代码。无论有没有弹出警报,Datatable 都可以正常工作,但警报弹出不适用于 datatable。只有没有它才能工作(数据表)。这是可能的代码冲突吗?当我尝试删除数据时,该错误表明 users.js:27(第 27 行)中出现“TypeError:无法设置未定义的属性‘操作’”。确认同样的事情(第 49 行)。

这是我的 HTML(表单)代码

<table class="table table-striped datatable" id="datatables">
                <thead>
                  <tr>
                    <th>#</th>
                    <th>First Name</th>
                    <th>Last Name</th>
                    <th>Username</th>
                  </tr>
                </thead>


                   <?php
                      if ($result->num_rows > 0) { // output data of each row?>
                       <tbody>
                           <?php  while($row = $result->fetch_assoc()) {
                              if($row['status']=='t'){
                      ?>
                              <form name="frmUser" action="" method="post"> 
                              <?php {                         //this form will display the set of pending applications

                                      echo'<tr>';
                                      echo '<td>' . '<input type="checkbox" name="selected[]" value="'.$row['application_number'].'" class="checkbox-warning"/>' . '</td>';
                                      echo '<td>' . $row['application_number'] . '</td>';
                                      echo '<td>' . $row['lastname'] . '</td>';
                                      echo '<td>' . $row['firstname'] . '</td>';
                                  echo'</tr>';
                                  }
                              ?>

                      <?php    } //if statement
                               } //while statement
                      ?>
                        </tbody>  
                      </table>
                          <input type="button" name="delete" value="Delete"  id="onDelete" />
                          <input type="button" name="update" value="Confirm"  id="onUpdate" />
                          </form>

                      <?php
                      }else {
                          echo "0 results";
                      }
            ?>

然后这是我的 JS 代码

jQuery(document).ready(function($){
$( "#onDelete" ).click(function() {
    swal({   title: "Are you sure?",   
        text: "You will not be able to recover this file!",   
        type: "warning",   
        showCancelButton: true,   
        confirmButtonColor: "#DD6B55",   
        confirmButtonText: "Yes, delete it!",   
        cancelButtonText: "No, cancel!",   
        closeOnConfirm: false,   
        closeOnCancel: false 
    }, function(isConfirm){   
        if (isConfirm) {
            document.frmUser.action = "temporary_applications_delete.php"; 
            document.frmUser.submit();       
            swal("Deleted!", "Application file has been deleted.", "success");

        } else {     
            swal("Cancelled", "Your file is safe :)", "error");   
        } });

});

$( "#onUpdate" ).click(function() {
    swal({   title: "Are you sure?",   
        text: "You will UPDATE this applicant file!",   
        type: "warning",   
        showCancelButton: true,   
        confirmButtonColor: "#DD6B55",   
        confirmButtonText: "Yes, UPDATE it!",   
        cancelButtonText: "No, cancel!",   
        closeOnConfirm: false,   
        closeOnCancel: false 
    }, function(isConfirm){   
        if (isConfirm) {
            document.frmUser.action = "temporary_applications_process.php"; 
            document.frmUser.submit();       
            swal("Updated!", "Application file has been updated!.", "success");

        } else {     
            swal("Cancelled", "Your file is safe :)", "error");   
        } });

});

});

代码出了什么问题?

4

1 回答 1

1

您有一个 html 问题,因为您在表格主体内打开表单标签并在表格后关闭它,您必须在表格主体内关闭表格,因为 html 标签必须正确关闭。

于 2015-10-26T07:28:20.277 回答