gpt4 book ai didi

javascript - 如何自定义 Bootstrap JS Popover

转载 作者:行者123 更新时间:2023-11-30 12:01:08 24 4
gpt4 key购买 nike

我使用 Bootstrap JS Popover 设计了带有年龄选择器的 HTML 页面 我得到了以下输出 1,我想实现输出 2 和以下任务

  1. li 列出作为输出 2 的内衬。
  2. li 应该可以点击,一旦点击 li 它应该出现在按钮文本中。

输出 1

输出 2

 $(document).ready(function() {
$('#age-select-1').popover({
content: "<ul><li>18</li><li>19</li><li>20</li><li>21</li><li>22</li><li>23</li><li>24</li><li>25</li></ul>",
html: true,
trigger: "focus",
placement: "bottom"
});
});
#age-select-1 li {
float: left; /*not working*/
display: inline; /*not working*/
}
<!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="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
</head>

<body>

<div class="container">
<label class="label nav-label">Age</label>
<button class="btn nav-age-select" id="age-select-1">21</button>
</div>
</body>

</html>

最佳答案

更改了列表中的 CSS - 给了它自己的类

基本上浏览器会添加它自己的内边距,所以我们只需重新调整它的形状,将宽度设置为 25% 即可获得效果

 $(document).ready(function() {
$('#age-select-1').popover({
content: "<ul class='foo'><li>18</li><li>19</li><li>20</li><li>21</li><li>22</li><li>23</li><li>24</li><li>25</li></ul>",
html: true,
trigger: "click",
placement: "bottom"
});
});
.foo { padding-left: 0; }
.foo li {
float: left;
display: inline-block;
width: 25%;
}
<!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="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
</head>

<body>

<div class="container">
<label class="label nav-label">Age</label>
<button class="btn nav-age-select" id="age-select-1">21</button>
</div>
</body>

</html>

关于javascript - 如何自定义 Bootstrap JS Popover,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36595859/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com