警报脚本:无法设置未定义的 属性 'action'

Alert Script : Cannot set property 'action' of undefined

我有一个代码,其中包含数据表和弹出警报。无论是否有警报弹出,数据表都可以正常工作,但警报弹出不适用于数据表。只有没有它才有效(数据表)。这可能是代码冲突吗?当我尝试删除数据时,该错误提示 "TypeError: Cannot set property 'action' of undefined" in users.js:27(第 27 行)。确认同样的事情(第 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");   
        } });

});

});

代码出了什么问题?

您有一个 html 问题,因为您在 table 正文中打开表单标签并在 table 之后关闭它 您必须在 table 正文中关闭表单 因为 html 标签必须正确关闭。