微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

javascript – jQuery .load()引导模态和显示

我试图在我的页面中.load()一个引导模态,并立即显示.以下是我编写的代码(它不起作用,因为模态打开,但可以永远不会关闭)!

基本上我试图在点击一个团队名称(与.team类)的时候以.形式()列出一个模态的玩家,我尝试过多种方式调用$($this).empty()成功.

这是我的功能

$(function () {

        $('.team').on('click',function () {

            var $this = $(this).data('target');

            $('#results-modals').load('/team-players.html ' + $this,function (response,status,xhr) {

                if (status == "success") {

                    $($this).modal({ show: true });
                }
            });
        });
  });

这里是html的锚点和示例模态:

<a class='team' data-toggle='modal' data-target='#20'>Real Madrid</a>

外部文件中的数据team-players.html:

<div id='20' class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
  <div class="modal-dialog modal-lg">
     <div class="modal-content">
       <p>Player 1: Ronaldo</p>
    </div>
  </div>
</div>

解决方法

而不是$($this).modal({show:true});尝试$(this).modal(‘show’);

要隐藏模态,可以使用$(this).modal(‘hide’);

原文地址:https://www.jb51.cc/jquery/153729.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐