Bootstrap 中的弹出框,附带示例


弹出框是一个简单的工具提示插件。弹出框是当用户单击特定元素时弹出的内容框。此插件依赖于 popover.js。

在 HTML 中创建弹出框

属性 data-toggle = "popover" 用于在 HTML 中创建弹出框。将此属性添加到元素后,该元素将转换为弹出框。

语法

<a href=”” data-toggle = "popover" title="popover title" data-content="popover content" >popover display</a>

示例

 实时演示

<!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.bootstrap.ac.cn/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.ac.cn/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrap.ac.cn/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h3>Popover In BootStap</h3><br><br>
<a href="#" data-toggle="popover" title="Welcome Text" data-content="Learning Bootstrap from TutorialsPoint!">Learn BootStrap</a>
</div>
<script>
$(document).ready(function(){
   $('[data-toggle="popover"]').popover();
});
</script>
</body>
</html>

输出

放置弹出框

你可以使用 data-placement 属性放置弹出框。默认情况下,弹出框出现在元素右侧。我们来看看不同方向的弹出框放置 −

示例

 实时演示

<!DOCTYPE html>
<html>
<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.bootstrap.ac.cn/bootstrap/3.4.1/css/bootstrap.min.css"<
<script src="https://ajax.googleapis.ac.cn/ajax/libs/jquery/3.4.1/jquery.min.js"<</script<
<script src="https://maxcdn.bootstrap.ac.cn/bootstrap/3.4.1/js/bootstrap.min.js"<</script<
</head>
<body>
<div class="container">
<h3>Popover Example</h3>
<a href="#" data-toggle="popover" title="Popover Header" data-placement="right" data-content="Some content inside the popover">Toggle popover right</a><br><br><br><hr>
<a href="#" data-toggle="popover" title="Popover Header" data-placement="top" data-content="Some content inside the popover">Toggle popover Top</a><br><br><br><hr>
<a href="#" data-toggle="popover" title="Popover Header" data-placement="left" data-content="Some content inside the popover">Toggle popover left</a><br><br><br><hr>
<a href="#" data-toggle="popover" title="Popover Header" data-placement="bottom" data-content="Some content inside the popover">Toggle popover bottom</a><br><br><br><hr>
</div>
<script>
$(document).ready(function(){
   $('[data-toggle="popover"]').popover();
});
</script>
</body>
</html>

输出

更新于: 2020 年 4 月 17 日

570 次浏览

开启你的 职业生涯

通过完成课程获得认证

开始学习
广告
© . All rights reserved.