使用两个 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/