2016-11-22 69 views
0

有兩個按鈕「按鈕1」用於顯示彈出窗口,「按鈕2」用於外部鏈接。增加了一些定製的jQuery的「按鈕1」 解僱酥料餅的時候,我們的身體任何地方挖掘,但其不工作在iPhone(其解僱,只有當龍頭在iphone相同的按鈕)Bootstrap popover關閉功能在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>

回答

0

「身體」標籤不工作在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'); 
      } 
     }); 
    });