在IE 11中单击后无法显示多个工具提示

问题描述

请帮助解决以下问题。 我试图在单击按钮时显示多个工具提示,并在单击第二次按钮时将其隐藏。由于某些原因,我无法在IE 11中执行此操作。在我提供的示例中,认情况下,我可以完美地在页面加载时显示它们。一旦我尝试点击(代码已注释掉),就什么也没发生。

<!DOCTYPE html>
<html lang="en">
<head>
    <title>Bootstrap Example</title>
    <Meta charset="utf-8">
    <Meta name="viewport" content="width=device-width,initial-scale=1">
    <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.3.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
    <div class="container">
        <h3>Demo</h3>
        <a href="#" data-toggle="tooltip" title="Tooltip is visible!">Tooltip will be visible here</a>

        <a href="#" data-toggle="tooltip" title="Tooltip is visible!">Tooltip will be visible here</a>
        <div>
            <button type="button" class="btn btn-primary">Show Tooltip</button>
            <button type="button" class="btn btn-default">Hide Tooltip</button>
        </div>
    </div>
    <script>
        //works fine  I can see tooltips by default
        $("[data-toggle='tooltip']").tooltip();
        $("[data-toggle='tooltip']").tooltip('show');

        $(document).ready(function () {
 
    $(".btn-primary").click(function () {
       //  doesn't work for some reson
      //  $("[data-toggle='tooltip']").tooltip();
       // $("[data-toggle='tooltip']").tooltip('show');
    });
    $(".btn-default").click(function(){
        $("[data-toggle='tooltip']").tooltip();
        $("[data-toggle='tooltip']").tooltip('hide');
    });
        });

      
           
        
    </script>
</body>
</html>

解决方法

<!DOCTYPE html>
<html lang="en">
<head>
    <title>Bootstrap Example</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <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.3.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
    <div class="container">
        <h3>Demo</h3>
        <a href="#" data-toggle="tooltip" title="Tooltip is visible!">Tooltip will be visible here</a>

        <a href="#" data-toggle="tooltip" title="Tooltip is visible!">Tooltip will be visible here</a>
        <div>
            <button type="button" class="btn btn-primary">Show Tooltip</button>
            <button type="button" class="btn btn-default">Hide Tooltip</button>
        </div>
    </div>
    <script>
        //make sure to comment this lines
        //works fine  I can see tooltips by default
      //  $("[data-toggle='tooltip']").tooltip();
       // $("[data-toggle='tooltip']").tooltip('show');

        $(document).ready(function () {
 
    $(".btn-primary").click(function () {
        // works fine on IE11
        $("[data-toggle='tooltip']").tooltip();
        $("[data-toggle='tooltip']").tooltip('show');
    });
    $(".btn-default").click(function(){
        $("[data-toggle='tooltip']").tooltip();
        $("[data-toggle='tooltip']").tooltip('hide');
    });
    });

      
           
        
    </script>
</body>
</html>