同时在SQL中加载Bootstrap模态

阿德里安

我有以下功能

function articlesList($limit) { ?>
 <div class="table-responsive rounded mb-20">
 <table class="table table-striped table-theme">
    <thead>
         <tr>
             <th style="width: 5%;" class="text-center border-right">ID</th>
             <th style="width: 10%;" class="text-center">Image</th>
             <th style="width: 50%;">Name</th>
             <th style="width: 20%;">Date</th>
             <th style="width: 15%;" class="text-center">Actions</th>
         </tr>
    </thead>
    <tbody>
 <?php $sql = "SELECT * FROM articles ORDER BY ID DESC";
 $items = mysql_query($sql);
 while ($art = mysql_fetch_array($items)) { 
 $id = "$art[ID]"; ?>
    <tr>
        <td class="text-center border-right"><?=$art[ID]?></td>
        <td class="text-center"><img src="../media/articles/<?=$art[image]?>" class="img-bordered-theme" width="45" height="45"></td>
        <td><?=$art[name]?></td>
        <td><?=$art[date]?></td>
        <td class="text-center">
        <a href="?act=edit&amp;id=<?=$art[ID]?>" class="btn btn-success btn-sm rounded" data-toggle="tooltip" data-placement="top" data-original-title="Edit"><i class="fa fa-pencil"></i></a>
        <a href="#" class="btn btn-danger btn-sm rounded" data-toggle="modal" data-target=".remove_<?=$art[ID]?>" data-placement="top" data-original-title="Remove"><i class="fa fa-times"></i></a>
        </td>
    </tr>
     <!-- Start MODAL EVENTS -->
     <div class="remove_<?=$art[ID]?> modal fade" tabindex="-1" role="dialog" aria-hidden="true">
         <div class="modal-dialog modal-md" style="margin-top: 200px;">
             <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title">Remove article</h4>
                </div>
                <div class="modal-body"><p>Are you sure you want to remove the article <b><?=$art[name]?></b>?</p></div>
                 <div class="modal-footer">
                     <form name="input" action="?act=remove" method="post">
                         <input type="hidden" name="id" value="<?=$art[ID]?>">
                         <input type="hidden" name="name" value="<?=$art[name]?>">
                         <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
                         <button type="submit" class="btn btn-danger">Remove</button>
                     </form>
                 </div>
             </div>
         </div>
     </div>
     <!-- End MODAL EVENTS -->
 <?php } ?>
 </tbody>
 </table>
 </div>
 <?php } //function 

我的问题是模态框。加载效果很好,传递了所有变量,但是在打开模态时发生了某些情况。

像这样的东西: 在此处输入图片说明

无法按下按钮,我无法关闭框或执行其他任何操作。

经过一些测试之后,如果我将模式代码放到while的底部,但是在此之外,模式运行良好。但是变量不能再传递了。

有什么办法吗?

希拉里

如果将模态置于循环之外,则可以使用BS模态事件函数将值传递给模

添加一个data-attribute模式触发按钮,例如data-id="<?=$art[ID]?>"<?=$art[ID]?>从中删除data-target

<a href="#" class="btn btn-danger btn-sm rounded" data-id="<?=$art[ID]?>" data-toggle="modal" data-target=".remove" data-placement="top" data-original-title="Remove"><i class="fa fa-times"></i></a>

而您必须传递给模态的第二个变量是<?=$art[name]?>,也向其添加另一个变量data-attribute例如data-value="<?=$art[ID]?>"

<td><span class="name" data-value="<?=$art[ID]?>"><?=$art[name]?></span></td>

注意:您可以添加data-value="<?=$art[ID]?>"到任何页面元素并将其传递给模式元素。

现在,模态HTML(在循环外部)将为注意:我<span class="Mname"></span>在模态中添加以显示名称,并添加id's到输入中以传递值

<!-- Start MODAL EVENTS -->
<div class="remove modal fade" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog modal-md" style="margin-top: 200px;">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                 <h4 class="modal-title">Remove article</h4>
            </div>
            <div class="modal-body">
                <p>Are you sure you want to remove the article <b><span class="pname"></span></b> ?</p>
            </div>
            <div class="modal-footer">
                <form name="input" action="?act=remove" method="post">
                    <input type="hidden" name="id" id="pid" value="">
                    <input type="hidden" name="name" id="pname" value="">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
                    <button type="submit" class="btn btn-danger">Remove</button>
                </form>
            </div>
        </div>
    </div>
</div>
<!-- End MODAL EVENTS -->

BS Modal事件侦听器脚本将是

$(document).ready(function(){ //Dom Ready
    $('.remove').on('show.bs.modal', function (e) { //Show event listener
        //Fetch val from modal button data-attribute
        var id = $(e.relatedTarget).data('id');
        //fetch name which match the data-attribute val of modal button
        var name = $('.name[data-value="' + id +'"]').html();
        //you can pass any on page variable or information to modal like this by creating more variables like `var name`
        //Now Pass it to modal
        $(".pname").html(name); 
        $("#pid").val(id);
        $("#pname").val(name);
    });
});

小提琴的例子

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

在Bootstrap 3模态中加载特定的外部内容

来自分类Dev

使Bootstrap模态加载更快

来自分类Dev

如何从AngularJS Bootstrap模态中的AJAX调用中加载JSON数据

来自分类Dev

在xpages中加载引导程序模态

来自分类Dev

Laravel在布尔中加载模态的问题

来自分类Dev

无法从Bootstrap加载示例模态

来自分类Dev

在php echo中加载bootstrap

来自分类Dev

如何在单个模态中加载任何局部

来自分类Dev

在 pyspark 中加载 SQL 查询?

来自分类Dev

加载时的Bootstrap-Angular-UI模态

来自分类Dev

Bootstrap(3.0.0)防止模态预加载内容

来自分类Dev

Android,ProgressBar setVisibility,同时在OnClickListener中加载数组

来自分类Dev

在SQL Server中加载XML返回null

来自分类Dev

使用SQL Loader在表中加载数据

来自分类Dev

使用SQL Loader在表中加载数据

来自分类Dev

jQuery事件未在已加载的Bootstrap模态窗口中绑定

来自分类Dev

Bootstrap-将远程Google Chart加载到模态

来自分类Dev

Google Maps在Bootstrap 3.0模态中无法完全加载

来自分类Dev

Bootstrap的模态无法从Struts2加载适当的值

来自分类Dev

Bootstrap 将远程表单加载到模态中

来自分类Dev

在页面加载时启动 Bootstrap 4v6 模态?

来自分类Dev

编辑 Bootstrap 模态弹出窗口未加载部分视图

来自分类Dev

使用或不使用ui-route在角度模态窗口中加载多个视图

来自分类Dev

在引导程序中以模态方式在轮播中加载特定的幻灯片

来自分类Dev

在angular js模态弹出窗口或部分视图中加载外部js文件

来自分类Dev

Bootstrap为什么尝试在Edge中加载LESS文件?

来自分类Dev

gulp在.net核心中加载bootstrap / jquery

来自分类Dev

Bootstrap类如何在我的文件中加载?

来自分类Dev

如何在WinJS iframe中加载远程内容,同时避免SEC7117错误?

Related 相关文章

  1. 1

    在Bootstrap 3模态中加载特定的外部内容

  2. 2

    使Bootstrap模态加载更快

  3. 3

    如何从AngularJS Bootstrap模态中的AJAX调用中加载JSON数据

  4. 4

    在xpages中加载引导程序模态

  5. 5

    Laravel在布尔中加载模态的问题

  6. 6

    无法从Bootstrap加载示例模态

  7. 7

    在php echo中加载bootstrap

  8. 8

    如何在单个模态中加载任何局部

  9. 9

    在 pyspark 中加载 SQL 查询?

  10. 10

    加载时的Bootstrap-Angular-UI模态

  11. 11

    Bootstrap(3.0.0)防止模态预加载内容

  12. 12

    Android,ProgressBar setVisibility,同时在OnClickListener中加载数组

  13. 13

    在SQL Server中加载XML返回null

  14. 14

    使用SQL Loader在表中加载数据

  15. 15

    使用SQL Loader在表中加载数据

  16. 16

    jQuery事件未在已加载的Bootstrap模态窗口中绑定

  17. 17

    Bootstrap-将远程Google Chart加载到模态

  18. 18

    Google Maps在Bootstrap 3.0模态中无法完全加载

  19. 19

    Bootstrap的模态无法从Struts2加载适当的值

  20. 20

    Bootstrap 将远程表单加载到模态中

  21. 21

    在页面加载时启动 Bootstrap 4v6 模态?

  22. 22

    编辑 Bootstrap 模态弹出窗口未加载部分视图

  23. 23

    使用或不使用ui-route在角度模态窗口中加载多个视图

  24. 24

    在引导程序中以模态方式在轮播中加载特定的幻灯片

  25. 25

    在angular js模态弹出窗口或部分视图中加载外部js文件

  26. 26

    Bootstrap为什么尝试在Edge中加载LESS文件?

  27. 27

    gulp在.net核心中加载bootstrap / jquery

  28. 28

    Bootstrap类如何在我的文件中加载?

  29. 29

    如何在WinJS iframe中加载远程内容,同时避免SEC7117错误?

热门标签

归档