jquery - 获取 Bootstrap 按钮的内部宽度(跨浏览器)

标签 jquery css twitter-bootstrap cross-browser

我正在尝试获取 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);

});
  1. 在按钮点击事件之前或之后获取的 innerWidth 不相等
  2. 使用的每个浏览器(IE10、Firefox、Chrome)的行为都不同

Bootply

我可以使用跨浏览器解决方案在点击事件前后获得相同的尺寸吗? 谢谢

最佳答案

您必须添加一些 CSS 才能使按钮在您单击时不会发生变化:

.btn:focus,.btn:active {
     outline: none !important;
}

Bootply of edited code with css

关于jquery - 获取 Bootstrap 按钮的内部宽度(跨浏览器),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30867332/

相关文章:

javascript - 本地登录/注册 Android Phonegap

html - CSS 背景图像不重复仅适用于 Firefox

javascript - 如何修复浏览器移动 View 中未定义问题的 jQuery 'length'?

html - 第二个 Bootstrap 导航栏与第一个导航栏的下拉菜单重叠?

jquery - 使用 bootstrap 的 Webpack - 未定义 jquery

jQuery:多次淡入淡出div

jQuery:选择所有内部链接,不包括可下载文件的链接

html - 居中固定宽度的 div 在左侧和右侧有流动的 div?

html - 复制 Bootstrap Carousel 箭头

javascript - 运行项目时的 Bootstrap/JQuery 问题