php - 单独文件上的引导模式不会关闭
问题描述
我正在使用bootstrap中的模态。模式打开,但没有使用十字或关闭按钮关闭。
这是我的index.php文件中的内容:
<div id="editar" class="modal fade" role="dialog" tabindex="-1" aria-hidden="true">
</div>
这是一个单独的.php文件中的模式:
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Editar Accion</h4>
<button type="button" class="close" data-dismiss="modal" id="cerrar">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<input type="hidden" name="editar" value="<?php echo $id; ?>">
<div class="form-group">
<label for="item_name">Accion:</label>
<input type="text" class="form-control" id="accion" value="<?php echo $accion; ?>">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary mb-3" name="update" id="btn-editar"><span class="glyphicon glyphicon-edit"></span> Editar</button>
<button type="button" class="btn btn-secondary mb-3" data-dismiss="modal"><span class="glyphicon glyphicon-remove-circle"></span> Cancelar</button>
</div>
</div>
</div>
我必须将它们保存在两个文件中。
解决方案
我认为最好使用它,JQuery
以便您可以更好地控制关闭时模式上发生的事情(例如:清除字段等)。
$(document).on('click','#button_id',function(e){
e.preventDefault();
//you can clear fields first if you need to
$('#accion').val('');
$('#modal_id').hide(); //close modal
});
请记住将文件包含在index.php
. 将模态保存在单独的文件中将有助于您在代码中的某处重用相同的内容,也就是说,如果您保持模态代码足够动态。
推荐阅读
- curl - 如何进行 curl 发布请求并仅获取状态码作为响应?
- r - R Shiny Dashboard,更改所有超链接的颜色
- html - 滚动容器中的粘页脚取决于内容的高度
- oracle - dbms_datapump.get_dumpfile_info 在存储过程中编译时无法读取目录
- rspec - 为什么我不能在 to_raise 匹配器中捕获 Capybara::ElementNotFound ?
- python - Google Cloud Text To Speech 中的权限错误 - Python
- frontend - Apollo 客户端缓存在没有参数的嵌套对象上使用 cacheRedirects 重定向
- json - 使用正文表单数据的 nativescript 发布请求
- key - Sublime Text Key Binding - 按空格键时括号之间的应用空间
- google-api - 来自浏览器的 Google Contacts API 被 CORS 政策阻止