doushanmo7024 2015-05-12 09:18
浏览 87
已采纳

Yii2当Bootstrap模态仍在加载时加载页面/图像

I have this modal:

<?php
    echo Html::button(
        'Create New Staff',
        [
            'value' => Url::to(['create-new-staff']),
            'class' => 'btn btn-success btn-create',
            'id' => 'modalButton'
        ]);

    Modal::begin(['id' => 'modal']);
    echo "<div id='modalContent'></div>";     
    Modal::end();
?>  

Here's my sample loading indicator image:

<img src="http://dkclasses.com/images/loading.gif" id="loading-indicator" style="display:none" />

When I click the modal button, I want to display a loading screen or image when the modal is still loading instead of just plainly waiting for the modal to load. I tried this:

<script type="text/javascript">
    $("modalButton").click(function(event) {
        $.post( "/echo/json/", { delay: 2 } );
        $(document).bind("ajaxSend", function(){
            $("#loading-indicator").show();
            }).bind("ajaxComplete", function(){
            $("#loading-indicator").hide();
            $("#modalContent").show();
         });
    });
</script>

I based that script in this fiddle.

And I also tried those I have searched in the internet. None of them worked. I think it's because I am using Yii. I'm not sure. How do I achieve this?

  • 写回答

2条回答 默认 最新

  • dousongqiang2585 2015-05-15 06:06
    关注

    Figured it out:

    $('#modalButton').click(function (){
        $('#modal').find('#modalContent').html("")
            .load($(this).attr('value'), function(){
                var thisModal = $('#modal');
                setTimeout(function(){
                    thisModal.modal('show');
                    $("#loading-indicator").hide();
                }, 1000);
            });
        $("#loading-indicator").show();
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料