jquery - 我可以动态更改引导弹出窗口标题样式吗
问题描述
这似乎是多次被问到的问题,但我无法让它在我的情况下工作。
我有一个表,其中包含带有背景颜色集的 td 元素。
当我设置弹出框(具有标题和内容图像)时,我想将标题设置为与 td 元素具有相同的背景颜色。
我正在使用 jquery 和 bootstratp 3.3.7 并且到目前为止有以下代码(工作正常)
...
$('td').hover(function(){
// mousein
$(this).popover({
animation: true,
container: 'body',
content : $(this).attr("popover-content"),
title : $(this).attr("popover-title"),
placement : "right",
html : "true",
trigger : "manual",
});
$(".popover-title").css('background-color',$(this).css('background-colo
r')+' !important');
$(this).popover('show');
},function(){
// mouseout
$(this).popover('hide');
});
...
不起作用的一点是对类 popover-title 上的 css 的更改。
我一定错过了一些重要的事情,所以会很感激一些帮助吗?
谢谢,保罗
解决方案
对于任何因这个特定问题而绊倒的人,这就是我解决它的方法。
1)通过添加一个链接到popover show事件的函数(在SO的相关文章中找到!)例如
<!-- bootstrap tooltip plugin -->
$('td').hover(function(){
// mousein
$(this).popover({
animation: true,
container: 'body',
content : $(this).attr("popover-content"),
title : $(this).attr("popover-title"),
placement : "right",
html : "true",
trigger : "manual",
}).on("show.bs.popover", function(){
if ($(this).attr("popover-content")) {
$(this).data("bs.popover").tip().css('background-color',$(this).css('background-color'));
} else {
$(this).data("bs.popover").tip().css('background-color','#107a9d');
}
});
$(this).popover('show');
},function(){
// mouseout
$(this).popover('hide');
});
- 通过使背景颜色“继承”什么是(大概)tip() css。
推荐阅读
- conduktor - 无法安装导体
- java - Android自动链接链接总是启动浏览器
- javascript - React Hooks,有条件地改变 onClick 函数中的状态,在下次点击时更新
- powershell - 修剪 Powershell 输出
- ios - 注销后如何关闭推送的 ViewController?
- javascript - Angular js(1.4)在ng-repeat中使用三元运算符来显示不同的html?
- javascript - JS中的HTML到PDF使用变量
- maven - 如何将 features 文件夹动态传递给 Jenkins->Maven->Testng Runner File
- android - 无法更新到 Android Studio 4.0
- python - 为什么powershell不断给我一个基于python的类程序的AttributeError?