Bootstrap popover dismiss功能无法在iphone

时间:2016-11-22 09:15:35

标签: javascript jquery html ios iphone

有两个按钮"按钮1和#34;用于显示弹出框和"按钮2"用于外部链接。为" Button 1"添加了一些自定义的jquery。当我们点击身体的任何地方时关闭popover ,但无法在iPhone上工作(仅在点按iphone中的相同按钮时才会解除)



$(document).ready(function () {
        $("body").tooltip({
            selector: "a[data-toggle='tooltip']",
            container: "body"
        })
                .popover({
                    selector: "a[data-toggle='popover']",
                    container: "body",
                    html: true
                });
    });

    $('body').on('click', function (e) {
        $('a[data-toggle="popover"]').each(function () {
            if(!$(this).is(e.target) &&
                    $(this).has(e.target).length === 0 &&
                    $('.popover').has(e.target).length === 0) {
                $(this).popover('hide');
            }
        });
    });

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

<div class="container" style="width:400px; height:400px; background:#000;padding-top:50px;"> 
  <a data-placement="top" role="button" class="btn btn-danger" data-toggle="popover" data-content="Popover" data-original-title="" title=""> Button1 </a> 
  <a class="btn btn-danger" href="http://facebook.com" target="_blank">Button2</a> </div>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

&#34;主体&#34;标签没有在iPhone上工作,我已经添加了一个类到正文。现在它的工作:

$(document).ready(function () {
        $("body").tooltip({
            selector: "a[data-toggle='tooltip']",
            container: "body"
        })
                .popover({
                    selector: "a[data-toggle='popover']",
                    container: "body",
                    html: true
                });
    });

    $('.bodyClass').on('click', function (e) {
        $('a[data-toggle="popover"]').each(function () {
            if(!$(this).is(e.target) &&
                    $(this).has(e.target).length === 0 &&
                    $('.popover').has(e.target).length === 0) {
                $(this).popover('hide');
            }
        });
    });