如何在jQuery / javascript中获取边框宽度 [英] How to get border width in jQuery/javascript

查看:505
本文介绍了如何在jQuery / javascript中获取边框宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何解析边框宽度



style =border:solid 1px black;

$ elem.css('border-width')/ p>

< )



不会这样做。



注意我需要解析width从css,作为元素 display:none



感谢



编辑我实际上并不使用内联样式,为了简单起见,我只是这样写,因为我没有意识到有任何行为差异。它似乎对内联样式很好,但仍然不能从应用的css类中获得任何值。

解决方案

s>您可以使用 parseInt(); Npx N

  var width = $ elem.css('borderWidth'); // 150px 
var parsed = parseInt(width); // 150



我有一个谷歌周围,它出现为了获得边框的宽度,你必须提供边界的一个明确的一面:

  var borderWidth = $ elem.css(border-left-width); 

这是因为每个边框都可能有不同的大小,样式和颜色。不幸的是,它似乎没有比这更简单。


How do I parse the border width from

style="border: solid 1px black;"

in jQuery/javascript?

$elem.css('border-width')

doesn't do it.

Note I need to parse the width from the css, as the element may be display:none

Thanks

Edit I'm not actually using an in-line style, I just wrote it that way for simplicity as I didn't realise there was any behavoural difference. It seems to work fine for inline styles though, but still can't get any value from an applied css class.

解决方案

You can just use parseInt(); to parse the border width from Npx to N:

var width = $elem.css('borderWidth'); // 150px
var parsed = parseInt(width);         // 150

I had a Google around and it appears in order to get the width of a border you must provide an explicit side of the border:

var borderWidth = $elem.css("border-left-width");

This is because it's possible for every border to have a different size, style and colour. Unfortunately it doesn't appear to be any simpler than this.

这篇关于如何在jQuery / javascript中获取边框宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆