1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>悬浮窗口</title>
<link rel="stylesheet" href="css/bootstrap.min.css" />
<!--JavaScript插件都是依赖jQuery库-->
<script type="text/javascript" src="js/jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
</head>
<body>
<a href="#" id="abc" class="btn btn-lg btn-danger" data-toggle="popover">xxxxxx</a>
<script>
$(function () {
$("[data-toggle='popover']").each(function () {
var element = $(this);
element.popover({
trigger: 'manual',
html: true,
title: 'kkkk',
placement: 'bottom',
content: function () {
return content();
}
}).on("mouseenter", function () {
$(this).popover("show");
}).on("mouseleave", function () {
$(_this).popover("hide")
});
});
});
//模拟动态加载内容(真实情况可能会跟后台进行ajax交互)
function content() {
var data = $("<form><ul>"
+ "<li><span aria-hidden='true'></span> <font>粉丝数:</font>7389223</li>"
+ "<li><span aria-hidden='true'></span> <font>关注:</font>265</li>"
+ "<li><span aria-hidden='true'></span> <font>微博:</font>645</li>"
+ "<li><span aria-hidden='true'></span> <font>所在地:</font>台湾</li>"
+ "<input id='btn' type='button' value='关注' onclick='test()'/></form>");
return data;
}
//模拟悬浮框里面的按钮点击操作
function test() {
alert('关注成功');
}
</script>
</body>
</html>
Post
Cancel
Bootstrap悬浮窗口(popover)
This post is licensed under
CC BY 4.0
by the author.