单击提交按钮后显示隐藏的表格

phpclever

我有一个表格,我在其中选择项目名称并输入工作表名称。单击提交按钮后,它以表格格式显示最后插入的记录,但单击提交后,它会显示表格,但一旦重新加载页面,它就会隐藏表格。并单击提交按钮,它会显示表格。我该如何解决这个问题?

<button type="submit" name="submit" id="button" class="btn-success btn">Submit</button>

<script>
  $(document).ready(function() {
    $("#button").click(function() {
      $("#table").show();
    });
  });
</script>

<?php 
  include('controller.php');
  $s4 = "SELECT * FROM col_heading ORDER BY coln_id DESC LIMIT 1";
  $res = mysqli_query($bd, $s4);
  while ($row = mysqli_fetch_array($res)) {
?>  

<table class="table table-bordered" id="table" style="width:50%;">
  <thead>
    <tr>
      <th>Sr.no</th>
      <th>Column Name</th>
    </tr>
  </thead>
  <tbody>

    <tr class="odd">
      <td>1</td>
      <td id="h1:<?php echo $row['coln_id']; ?>" contenteditable="true">
        <?php  echo $row['h1']; ?>
      </td>       
    </tr>
    <tr>
      <td>2</td>
      <td id="h2:<?php echo $row['coln_id']; ?>" contenteditable="true">
        <?php echo $row['h2']; ?>
      </td>
      </tr>
    <tr class="odd">
      <td>3</td>
      <td id="h3:<?php echo $row['coln_id']; ?>" contenteditable="true">
        <?php echo $row['h3']; ?>
      </td>
    </tr>
  </tbody>
</table>
<?php 
} 
?>
纳迪尔·拉斯卡尔

尝试e.preventDefault();在您的提交中使用。

$(document).ready(function() {
  $("#button").click(function(e) {
    e.preventDefault();
    $("#table").show();
  });
});

如果你想在提交时做一些事情,那么最好在 click 函数中使用 ajax 调用并完成它。

将你的 php 放在一个新文件中

更新.php

<?php 
  include('controller.php');
  $s4 = "SELECT * FROM col_heading ORDER BY coln_id DESC LIMIT 1";
  $res = mysqli_query($bd, $s4);
  while ($row = mysqli_fetch_array($res)) {
?>

从内部单击函数对 update.php 进行 ajax 调用

 $(document).ready(function() {
      $("#button").click(function(e) {
        e.preventDefault();
        $("#table").show();
        $.ajax({
           url: 'update.php',
           data: '<pass any data here>',
           success: function(response){
             // do something with the resposne
           }
        });
      });
    });

完整代码

<button type="submit" name="submit" id="button" class="btn-success btn">Submit</button>

<script>
  $(document).ready(function() {
      $("#button").click(function(e) {
        e.preventDefault();
        $("#table").show();
        $.ajax({
           url: 'update.php',
           data: '<pass any data here>',
           success: function(response){
             // do something with the resposne
           }
        });
      });
    });
</script>


<table class="table table-bordered" id="table" style="width:50%;">
  <thead>
    <tr>
      <th>Sr.no</th>
      <th>Column Name</th>
    </tr>
  </thead>
  <tbody>

    <tr class="odd">
      <td>1</td>
      <td id="h1:<?php echo $row['coln_id']; ?>" contenteditable="true">
        <?php  echo $row['h1']; ?>
      </td>       
    </tr>
    <tr>
      <td>2</td>
      <td id="h2:<?php echo $row['coln_id']; ?>" contenteditable="true">
        <?php echo $row['h2']; ?>
      </td>
      </tr>
    <tr class="odd">
      <td>3</td>
      <td id="h3:<?php echo $row['coln_id']; ?>" contenteditable="true">
        <?php echo $row['h3']; ?>
      </td>
    </tr>
  </tbody>
</table>

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

填写第一个表格并单击提交按钮后,显示“隐藏”表格

来自分类Dev

单击后隐藏提交按钮

来自分类Dev

显示单击显示按钮时隐藏表格

来自分类Dev

表单仅在单击提交按钮后显示

来自分类Dev

单击提交按钮后,如何在其下方显示隐藏的部分?

来自分类Dev

单击提交按钮后,如何在其下方显示隐藏的部分?

来自分类Dev

单击后显示更多隐藏按钮

来自分类Dev

单击按钮时隐藏/显示表格中的按钮

来自分类Dev

单击添加按钮后未显示提交按钮(AngularJS)

来自分类Dev

单击后隐藏按钮

来自分类Dev

单击后隐藏按钮

来自分类Dev

单击按钮后,在Angular中隐藏按钮并显示数据

来自分类Dev

单击一个按钮以显示或隐藏表格

来自分类Dev

如何通过单击按钮隐藏和显示表格?

来自分类Dev

jQuery:根据单击的按钮隐藏/显示表格行

来自分类Dev

根据日期隐藏表格行并单击按钮再次显示它们

来自分类Dev

单击按钮显示表格

来自分类Dev

提交后隐藏表格行

来自分类Dev

单击按钮后,我想显示表格并打开新窗口

来自分类Dev

单击后隐藏并显示两个按钮

来自分类Dev

通过滚动按钮单击隐藏后显示工具栏

来自分类Dev

单击按钮后显示图片,并在加载iframe时隐藏

来自分类Dev

角度方式:单击按钮后显示或隐藏元素

来自分类Dev

单击后隐藏并显示两个按钮

来自分类Dev

AngularJS:单击后隐藏按钮

来自分类Dev

提交后再次显示表格

来自分类Dev

单击提交按钮显示输入

来自分类Dev

单击按钮即可显示表格

来自分类Dev

单击按钮隐藏并显示div