我正在尝试获取 Bootstrap 按钮的大小(宽度),但我有一些奇怪的行为。
<div class="row">
<div class="col-md-4 col-md-offset-4">
<button type="button" class="btn btn-warning btn-sm">
<span class="glyphicon glyphicon-floppy-disk" aria-hidden="true"></span> Save This Item
</button>
</div>
</div>
j查询
var siHeight = $('button').innerHeight();
var siWidth = $('button').innerWidth();
$('button').on('click', function() {
var iHeight = $('button').innerHeight();
var iWidth = $('button').innerWidth();
alert("On click H x W" + iHeight + " x " + iWidth + " Before click H x W " + siHeight + " x " + siWidth);
});
- 在按钮点击事件之前或之后获取的 innerWidth 不相等
- 使用的每个浏览器(IE10、Firefox、Chrome)的行为都不同
我可以使用跨浏览器解决方案在点击事件前后获得相同的尺寸吗? 谢谢
最佳答案
您必须添加一些 CSS 才能使按钮在您单击时不会发生变化:
.btn:focus,.btn:active {
outline: none !important;
}
关于jquery - 获取 Bootstrap 按钮的内部宽度(跨浏览器),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30867332/