javascript - 使用 Bootstrap 模态代替 Colorbox

标签 javascript php jquery twitter-bootstrap colorbox

我有以下 javascript,它会触发 colorbox 使用服务器上的参数打开特定的 PHP 页面:

$(document).ready(function() {   
    $('#example tbody').on( 'click', 'input', function () { 
        var data = table.row( $(this).parents('tr') ).data();

        $(".iframe").colorbox({iframe:true, width:"700px", height:"80%", href:"session_edit.php?ID="+data[0]});
        $(".iframe2").colorbox({iframe:true, width:"700px", height:"80%", href:"index_b.html?ID="+data[0]});
        $(".iframe3").colorbox({iframe:true, width:"300px", height:"20%", href:"delete.php?ID="+data[0], onLoad: function() {
            $('#cboxClose').remove()        
        }});

    });
});

不,我想使用 Bootstrap 模式而不是 colorbox。我尝试过:

$("#iframe").modal('show');

但是它不起作用,也不知道如何用 ?ID= 指定 PHP 文件

知道如何解决这个问题吗?

谢谢

最佳答案

您的问题有点不清楚什么不起作用,但我认为您正在尝试将远程 php 文件加载到 Bootstrap 模式中,该文件不像颜色框中那样显示,并且希望用 Bootstrap 模式替换颜色框

您可以在 Bootstrap 模式调用按钮 href="session_edit.php?ID=<?php echo $id;?>"> 中添加这样的远程文件并使用 ?ID=

指定 PHP 文件
<button class="btn btn-primary" data-toggle="modal" data-target="#iframe" href="session_edit.php?ID=<?php echo $id;?>">Open Modal</button>

您不需要 jQuery 来调用模态,让 bootstrap 默认模态功能完成它的工作

要触发模态窗口,您需要包含两个 data-* 属性:

data-toggle="modal" //opens the modal window
data-target="#iframe" //points to the id of the modal

所以你不需要这个 jQuery 代码来显示 Bootstrap 模式

$("#iframe").modal('show');

模态 HTML 将是

<div class="modal fade" id="iframe" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
    <div class="modal-content">
         //Content loads here
    </div>
</div>
</div>

同样在远程 php 文件中您可以添加 moda-header , modal-bodymodal-footer

远程 php session_edit.php

<div class="modal-header">
    <button type="button" class="close" data-dismiss="modal">&times;</button>
    <h4 class="modal-title"><center>Heading</center></h4>
</div>
<div class="modal-body">
    //Show what ever content here you like it will load into the modal
</div>
<div class="modal-footer">
    <button type="button" class="btn btn-default">Submit</button>
    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>

最后,如果您在同一页面上处理多个模态而不刷新页面,则可能需要刷新模态内容

<script>
$( document ).ready(function() {
    $('#iframe').on('hidden.bs.modal', function () {
          $(this).removeData('bs.modal');
    });
});
</script>

希望这有帮助。

关于javascript - 使用 Bootstrap 模态代替 Colorbox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32646170/

相关文章:

javascript - 在 Canvas 上画一个漂亮的激光(星球大战)

php - 如果复选框被选中,Laravel Store Value

php - Codeigniter 无法连接到外部 SQL Server

javascript - MVC 中的 JQuery - 使用 getJson 将表单数据作为数组发送

javascript - React Native 组件中的 onEnter/onExit 方法 (react-native-router-flux)

javascript - 当我使用另一个 iframe 时,如何从主页向 iframe 发送数据?

javascript - 如果 HTML 标签为空,则添加类

javascript - 来自同一类动态列表的函数

javascript - IE 显示错误 - 对象不支持此属性或方法

javascript - Bootstrap - 键盘无法在动态生成的文本框软搜索菜单上工作