Javascript 使用 php 调用引导模式显示事件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14685555/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Call bootstrap modal show event with php
提问by pckmn
I want to call modal('show')event with php code. How can I do this? I tried the following:
我想modal('show')用php代码调用事件。我怎样才能做到这一点?我尝试了以下方法:
if(isset($_POST['Edit'])){
echo "<script> $('#Modal').modal('show') </script>";}
I run this code, but echo "<script> $('#Modal').modal('show') </script>";doesnt work. How can I show modal when image input is clicked? I don't want to call with image onlick.
我运行此代码,但echo "<script> $('#Modal').modal('show') </script>";不起作用。单击图像输入时如何显示模态?我不想用图像 onlick 打电话。
Input:
输入:
<input type="image" src="image.png" name="Edit" value="Edit" alt="Edit" />
Modal:
模态:
<div class="modal hide fade" id="Modal" >
<form method="post">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" style="margin-top:-10px">×</button>
</div>
<div class="modal-body">
<textarea id="text" name="text">Test</textarea>
</div>
<div class="modal-footer">
</div>
</form>
</div>
回答by user3133586
Set the document.ready function as shown below:
如下设置 document.ready 函数:
echo "<script type='text/javascript'>
$(document).ready(function(){
$('#Modal').modal('show');
});
</script>";
On a side note, this work around is also great if you have a modal login form and need to alert the user on submit (or $_POST) for any submission errors in a seperate modal.
附带说明一下,如果您有一个模态登录表单并且需要在提交(或 $_POST)时提醒用户在单独的模态中出现任何提交错误,则此解决方法也很棒。
回答by Devang Rathod
You can use jquery fadeIn function to show model
您可以使用 jquery 的淡入功能来显示模型
$('#Modal').modal('show');
Change to
改成
$('#Modal').fadeIn('show');
Hope it will help you.
希望它会帮助你。

