我正在尝试在“ if”语句的结果后显示一个模式对话框,而没有一个可以打开它的按钮,是否有任何方法可以仅使用条件语句的响应来显示它?
当前,我正在Model View Controller中进行开发。因此,当我拨打电话时,我会在控制器中执行以下操作:
if($response == "success"){
<script>
$(function() {
$('#eventCreated').modal('show');
});
</script>
}
和我视图底部的模式如下:
<div class="modal fade" id="eventCreated" tabindex="-1" role="dialog" aria-
labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel">Great!</h4>
</div>
<div class="modal-body">
This is test
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-
dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">create</button>
</div>
</div>
</div>
</div>
答案 0 :(得分:0)
希望这对您有所帮助,毕竟这取决于响应。我使用响应变量仅显示演示
var response = "success";
if (response == "success") {
$('#eventCreated').modal('show');
}
$("button").click(function(){
var response = "success";
if (response == "success") {
$('#eventCreated').modal('show');
}
});
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h2>Modal Example</h2>
<!-- Button to Open the Modal -->
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal">
Open modal
</button>
<!-- The Modal -->
<div class="modal" id="eventCreated">
<div class="modal-dialog">
<div class="modal-content">
<!-- Modal Header -->
<div class="modal-header">
<h4 class="modal-title" id="myModalLabel">Great!</h4>
</div>
<div class="modal-body">
This is test
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">create</button>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
答案 1 :(得分:0)
尝试一下:
private function _assertValidAddress($address)
{
if (!preg_match('/^'.$this->getGrammar()->getDefinition('addr-spec').'$/D',
$address)) {
throw new Swift_RfcComplianceException(
'Address in mailbox given ['.$address.
'] does not comply with RFC 2822, 3.6.2.'
);
}
}
否则,您必须打印$ response的值。