在jQuery中获取弹出窗口的宽度 [英] Get popover width in jquery
本文介绍了在jQuery中获取弹出窗口的宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个悬停在其上的弹出窗口.弹出窗口的宽度将根据其内容而定.
I have popover which display on hover. The width of the popover will be according to its content.
$("[rel='popover']").on('show.bs.popover', function () {
//How to get popover width
});
我想在悬停时获得弹出窗口的宽度.
I want to get the popover width when hovering.
推荐答案
有两种方法:
由属性描述的咏叹调
您可以通过查看按钮的'aria- describeby'属性来获得弹出框的元素(并由此获得宽度).请注意,只有在显示弹出窗口后才能获取此属性.
You can get the popover's element (and thus the width) by looking at the 'aria-describedby' attribute of the button. Note you can only get this attribute once the popover has been shown.
所以
$("[rel='popover']").on('shown.bs.popover', function () {
var popoverID = $(this).attr('aria-describedby')
console.log($("#"+popoverID).width());
});
.next()
在弹出窗口显示之后,您也可以使用jQuery .next()获取对象.
You can also get the object using jQuery .next(), again after the popover is shown.
所以
$("[rel='popover']").on('shown.bs.popover', function () {
console.log($($(this).next()).width());
});
这篇关于在jQuery中获取弹出窗口的宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文