php - 在单独的 php 文件上定义 Bootstrap 按钮

标签 php jquery html twitter-bootstrap-3

使用两个 php 文件,index.php 和 search.php。 index 向 search 发送一些参数,它对数据库执行一些查询,然后返回表上的信息,存储到 $output 中。 我现在想在输出中添加一个引导按钮,它调用一个简单的显示/隐藏 jQuery 函数。 按钮已创建,但在 index.php 上测试时它不起作用

<div class="col-sm-8">
        <table class="table table-hover" id="output">
        </table>

        <div id="edit" >
          <div class="page-header" id="editar" style="display: none;">
            <h2 id="producto">Placeholder<button id="exit" type="button" class="btn pull-right"><span class="glyphicon glyphicon-remove"></button><!--Clicking this button hides the edit div and shows the output table--></h2>
          </div>
        </div>
  </div>

exit/editbtn 按钮调用以下内容:

  <script>
    $(document).ready(function(){
       $("#exit").click(function(){
          $(document.getElementById("edit")).hide();
          $(document.getElementById("output")).show();
       });
    });
    $(document).ready(function(){
       $("#editbtn").click(function(){
          $(document.getElementById("edit")).show();
          $(document.getElementById("output")).hide();
       });
     });
</script>

“editbtn”的定义是在单独的 php 文件中进行的:

if($query->num_rows){
  $rows = $query->fetch_all(MYSQLI_ASSOC);
  forEach($rows as $row){
    $output .=  '<tr><td><button id="editbtn" type="button" class="btn btn-default"><span class="glyphicon glyphicon-pencil"></span></button></td><!--Clicking this button hides the output table and shows the edit div--></tr>'; 
  }
  $output .= '</tbody>';

所以最后,我创建了带有按钮的表格,但是当我点击它时它什么也没做。

最佳答案

你为什么不按顺序尝试相同的东西?

喜欢:

<script>
    $(document).ready(function(){
       $("#exit").click(function(){
          $("#edit").hide();
          $("#output").show();
       });

       $("#editbtn").click(function(){
          $("#edit")).show();
          $("#output")).hide();
       });
     });
</script>

这应该有效,总是你不会根据定义插入带有 ajax AND 的编辑按钮,如果你使用 ID,你应该只有一个元素,如果你在 foreach 之间有它,这可能会给您带来麻烦。

关于php - 在单独的 php 文件上定义 Bootstrap 按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32404227/

相关文章:

php - 尝试从数据库中获取 json 数据时获取 MYSQL 错误代码

HTML 表格到 emacs 表格?

gwt - 是否有针对 GWT 的 HTML5 Canvas 对象的完整实现?

javascript - Jasmine 测试在网络浏览器中测试 javascript 上传文件

javascript - php脚本的for循环内的onkeyup函数

php - 在 Laravel 中查看如何对 URL 进行 json_decode

javascript - WordPress 插件表单未提交

javascript - Twitter bootstrap 通过 Javascript in rails 管理多个单选按钮

javascript - jquery 根据选定的下拉值循环进行计算

javascript - 添加计时器以在将产品添加到购物车后关闭 Ajax Quick Cart (Shopify)?