【问题标题】:Call bootstrap modal show event with php使用 php 调用引导模式显示事件
【发布时间】:2013-02-04 11:13:00
【问题描述】:

我想用 php 代码调用modal('show') 事件。我怎样才能做到这一点?我尝试了以下方法:

if(isset($_POST['Edit'])){
echo "<script> $('#Modal').modal('show') </script>";} 

我运行此代码,但 echo "&lt;script&gt; $('#Modal').modal('show') &lt;/script&gt;"; 不起作用。单击图像输入时如何显示模态?我不想用图片 onlick 打电话。

输入:

<input type="image" src="image.png" name="Edit" value="Edit" alt="Edit" />

模态:

<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>

【问题讨论】:

  • 确保在加载 jquery 和 bootstrap.js 后回显脚本
  • 还要确保图像输入周围有一个表单,其方法设置为 post
  • 最后一条评论,一些浏览器(IE、FireFox)没有在图像输入上接收到名称(它们接收到单击位置的 x、y 坐标see this),可能需要在你的 isset 中尝试$_POST['Edit_x']
  • 当我使用onlick图像输入时,它可以工作。我认为 .js 已加载。
  • 我确定帖子没问题。我觉得是php和js代码问题,不是ie什么的。

标签: php javascript jquery twitter-bootstrap


【解决方案1】:

如下图设置document.ready函数:

echo "<script type='text/javascript'>
$(document).ready(function(){
$('#Modal').modal('show');
});
</script>";

附带说明,如果您有一个模态登录表单并且需要在提交(或 $_POST)时提醒用户在单独的模态中出现任何提交错误,则此解决方法也很棒。

【讨论】:

    【解决方案2】:

    你可以使用jquery的fadeIn函数来显示模型

    $('#Modal').modal('show');
    

    改成

    $('#Modal').fadeIn('show');
    

    希望对你有帮助。

    【讨论】:

    • 检查 if(isset($_POST['Edit'])){ echo "hello"; } ,它的回声与否?
    • 检查:bootstrap.js 加载了吗?
    猜你喜欢
    • 1970-01-01
    • 2017-02-02
    • 1970-01-01
    • 2020-09-11
    • 1970-01-01
    • 2014-08-08
    • 1970-01-01
    • 2019-05-10
    相关资源
    最近更新 更多