我使用Bootstrap模式为用户显示一些内容'错误,这是我的代码:
<div class="modal fade" id="modal1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
<h4 class="modal-title text-warning">ERROR</h4>
</div>
<div class="modal-body text-warning" id="a">You need to login to leave your comments.
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Login</button>
</div>
</div>
</div>
</div>
<!-- second modal -->
<div class="modal fade" id="modal2">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
<h4 class="modal-title text-warning"></h4>
</div>
<div class="modal-body text-warning">Please fill all these fields for more accurate results
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Login</button>
</div>
</div>
</div>
</div>
然后我使用2个变量来确定将显示哪个模态。问题是我的代码仅在我使用1模态时有效,当我添加另一个模态时,它不会显示任何内容。有人可以指出我的错误吗?
EDITED 这是我的完整代码
<?php
$error1 = "";
$error2 = "";
if ((isset($_POST["MM_insert_comment"])) && ($_POST["MM_insert_comment"] == "form")) {
if($autologin){
$fac = $_POST["facilities"]; $fee = $_POST["fee"];
$qua = $_POST["quality"]; $act = $_POST["activities"];
//$name = $_SESSION['MM_Username'];
$name = $real_username;
if ( ($fac!=NULL)&&($fee!=NULL)&&($qua!=NULL)&&($act!=NULL) ){
$insertSQL = sprintf("INSERT INTO comment (facilities,fee,quality,activities,UserName)
VALUES ('$fac','$fee','$qua','$act','$name')");
mysqli_query($localhost,$insertSQL) or die(mysqli_error($localhost));
header('Location: '.$thispage);
}
else {
$error1 = true;
}
} else {
$error2= true;
}
}?>
和Js代码显示模态:
<script type="text/javascript">
$(document).ready(function(){
var error1 = <?php echo $error1; ?>;
if(error1){
$('#modal1').modal('show');
}
var error2 = <?php echo $error1; ?>;
if(error2){
$('#modal2').modal('show');
}
});
</script>
//我不认为我的问题是关于这段代码的,所以我之前没有发布过它:)