我正在使用 Bootstrap 弹出框实现类似 HTML5 的错误工具提示。与 HTML5 版本一样,我想对工具提示应用偏移量,使其向右移动。尽我所能,我未能完成此任务。
我尝试了几种模板方法,但都没有成功。 Bootstrap Popover document将“offset”显示为一个选项并指向一个神秘的 Tether document .添加偏移选项(例如偏移量:'0 25%')似乎也不起作用。
validate.issueError = function ($elem, msg, placement) {
placement = placement == undefined ? 'bottom' : placement;
var offset = $elem.width() / 4;
var template = '<div class="popover" style="position:relative; margin-left:' + offset + 'px" role="tooltip"><div class="popover-arrow"></div><h3 class="popover-title"></h3><div class="popover-content"></div></div>'
console.log("template="+ template)
$elem.prop('data-toggle=popover', true);
var exclamationPoint = "<span style='font-weight: bold; font-size:medium; color: white; background-color: orange; height: 12px; padding: 1px 8px; margin-right: 8px;'>!</span>";
var content = "<span style='font-size: smaller;'>" + msg + "</span>";
$elem.popover("destroy").popover({
html: true,
placement: placement,
template: template,
content: exclamationPoint + content
}).popover('show');
setTimeout(function () { $elem.popover('hide') }, 5000);
$elem.focus();
$elem.on("keydown click", function () {
console.log("kd?")
$(this).popover('hide');
})
}
最佳答案
您是否尝试将其作为数据属性传递? data-offset
就是具体的那个。这是一个 example对于按钮
。
关于javascript - 有没有人掌握了 Bootstrap popover offset 选项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38753840/