Bootstrap Modal显示在一个页面上,但不显示在另一个页面
Bootstrap Modal shows up on one page but not the other?
我正在尝试使用Bootstrap对网站进行编码。我已经在一个页面上使用了模态(这里)实现了它,而另一个页面似乎没有在该页面上显示模态(那里),有一个按钮可以编辑禁令的详细信息,但当我单击编辑按钮时,它什么也不做。
此外,我使用jQuery提交表单,这样我就可以重定向到返回的ID,但是,我一直纠结于我的函数如何返回ID,因为使用get_mysql()->fetch_assoc($result)["id"]
导致500内部服务器错误。代码可在下面找到。
ban.php
<div class="modal fade" id="modal" tabindex="-1" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title">Edit Ban</h4>
</div>
<form id="form">
<div class="modal-body">
<div class="form-group">
<input type="text" value="<?php echo $ban["uuid"] ?>" id="uuid" name="uuid" placeholder="UUID" class="form-control"/>
</div>
<div class="form-group">
<input type="text" value="<?php echo $ban["reason"] ?>" id="reason" name="reason" placeholder="Reason" class="form-control"/>
</div>
</div>
<input type="hidden" id="id" name="id" value="<?php echo $ban["id"] ?>" />
<div class="modal-footer">
<input type="submit" class="btn btn-primary"/>
</div>
</form>
</div>
</div>
</div>
<script>
$(document).ready(function() {
$("#form").submit(function(e) {
e.preventDefault();
var uuid = $("#uuid").val();
var reason = $("#reason").val();
$.post("add.php", { id: id, uuid: uuid, reason: reason, key: "<?php echo get_key() ?>" }, function(data) {
location.href = "ban.php?id=<?php echo data ?>";
});
});
});
</script>
index.php
<div class="modal fade" id="modal" tabindex="-1" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title">Add Ban</h4>
</div>
<form id="form">
<div class="modal-body">
<div class="form-group">
<input type="text" value="<?php echo $ban["uuid"] ?>" id="uuid" name="uuid" placeholder="UUID" class="form-control"/>
</div>
<div class="form-group">
<input type="text" value="<?php echo $ban["reason"] ?>" id="reason" name="reason" placeholder="Reason" class="form-control"/>
</div>
</div>
<div class="modal-footer">
<input type="submit" class="btn btn-primary"/>
</div>
</form>
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script>
$(document).ready(function() {
$("#form").submit(function(e) {
e.preventDefault();
var uuid = $("#uuid").val();
var reason = $("#reason").val();
$.post("functions/add.php", { uuid: uuid, reason: reason, key: "<?php echo get_key() ?>" }, function(data) {
location.href = "functions/ban.php?id=<?php echo data ?>";
});
});
});
</script>
api.php
<?php
define("key", "redacted");
function get_mysql() {
$mysql = new mysqli("localhost", "redacted", "redacted", "redacted");
if($mysql->connect_error) {
die($mysql->connect_error);
}
return $mysql;
}
function add($uuid, $reason) {
$date = gmdate("Y-m-d H:i:s");
get_mysql()->query("insert into bans (uuid, date, reason) values ('$uuid', '$date', '$reason')");
$result = get_mysql()->query("select id from bans where uuid = '$uuid' and date = '$date' and reason = '$reason'");
get_mysql()->fetch_array($result);
return $result["id"];
}
function update($id, $uuid, $reason) {
get_mysql()->query("update bans set uuid = '$uuid', reason = '$reason' where id = $id");
}
function remove($uuid) {
get_mysql()->query("delete from bans where uuid = '$uuid'");
}
function remove_by_id($id) {
get_mysql()->query("delete from bans where id = $id");
}
function get($uuid) {
return get_mysql()->query("select * from bans where uuid = '$uuid'")->fetch_assoc();
}
function get_by_id($id) {
return get_mysql()->query("select * from bans where id = $id")->fetch_assoc();
}
function get_bans() {
return get_mysql()->query("select * from bans");
}
function login($username, $password) {
$password = hash("sha256", $password);
return get_mysql()->query("select count(*) from users where username = '$username' and password = '$password'")->num_rows > 0;
}
function register($username, $password) {
$password = hash("sha256", $password);
get_mysql()->query("insert into `users` (`username`, `password`) values ('$username', '$password'");
}
function get_key() {
return key;
}
?>
多亏@statin88,我找到了答案。我没有提供bootstrap.min.js(facepalm)的正确链接
再次感谢@statin88。
相关文章:
- bootstrap消除模态并显示另一个模态
- 如果显示另一个折叠的图元,如何隐藏该图元
- Javascript:当这个单词被点击5次时,下面会显示另一个单词
- 如何使用引导程序显示另一个导航栏而不是下拉菜单
- 通过点击隐藏DIV,并通过JavaScript显示另一个DIV
- 如何使一个按钮在单击时显示另一个按钮
- 角度 ui-select 绑定到一个属性,但向用户显示另一个属性
- 基础 4 - 图像滚动以显示另一个图像
- 一个 iframe 上的按钮以显示另一个 iframe
- 在当前选项卡中按下按钮时显示另一个选项卡
- 如果背景图像不存在,则在角度中显示另一个背景
- 在加载备用图像时显示另一个图像
- 使用 Jquery 显示另一个 Div 中的动态 Div 数
- 如何隐藏一个锚标记并在同一位置显示另一个锚标记
- 显示一个图像,然后使用 HTML 显示另一个图像
- 如何隐藏和显示另一个选择选项栏的选择选项
- 验证表单,然后使用 jQuery 显示另一个隐藏表单
- Vaadin 日历:如何在事件单元格上显示另一个属性
- 如何确保提交表单时未显示另一个(新)页面
- 选择框根据所选内容显示另一个