大家好!我正在将Laravel 5.2用于Web应用程序。在此应用程序中,用户可以上传文件。当用户想要上传文件但未选择文件时,他们Redirect::to
上传页面,其中包含有关选择要上传文件的消息status
。过去使用此代码显示消息的网页:
@if (session('status'))
<div class="alert alert-warning">
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
{{ session('status') }}
</div>
@endif
哪个效果很好!但是由于CSS和JQuery模拟,我希望有一个带有消息的弹出窗口。我去搜索了一些东西,我发现Bootstrap Modal是最好的。我将代码调整为:
@if (session('status'))
<div class="modal fade">
<div class="modal-dialog" role="document">
<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">Modal title</h4>
</div>
<div class="modal-body">
<p>{{ session('status') }}</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
@endif
但现在,没有显示任何内容!有人可以帮我解释为什么模态不可视化?
所以我尝试了Mayank Pandeyz的回答。然后检查浏览器。这表明使用正确的状态消息调用Modal!
Consule错误是:Uncaught ReferenceError: $ is not defined
答案 0 :(得分:0)
试试这个:
@if (session('status'))
<div class="modal fade" id="myModal">
<div class="modal-dialog" role="document">
<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">Modal title</h4>
</div>
<div class="modal-body">
<p>{{ session('status') }}</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<script>
$('#myModal').modal('show'); // You have to initialize it as a modal
</script>
@endif