getComputedStyle 或 currentStyle 用于边框左宽
getComputedStyle or currentStyle for border-left-width
My HTML : <div id="bar" ></div>
我的 CSS :
#bar
{
border-left-width:150px;
}
我的 JS :
function getStyle(el,styleProp)
{
if(el.currentStyle)var y=el.currentStyle[styleProp];
else if(window.getComputedStyle)var y=document.defaultView.getComputedStyle(el,null).getPropertyValue(styleProp);
return y;
}
alert(getStyle(document.getElementById("bar"),"border-left-width"));//Outputs 0px
小提琴:http://jsfiddle.net/4ABhZ/1
如何获得border-left-width
房产?(使用我的示例,它不起作用(在火狐上))
检查您的border-left-style
属性。它设置为 none
(默认值)。将其设置为类似于solid
,您就可以开始了:http://jsfiddle.net/Paulpro/4ABhZ/4/
要支持较旧的浏览器,您需要将带连字符的css更改为camelCase。
您也可以在其他浏览器中使用驼峰,并且直接读取 getComputedStyle 对象的属性。
function getStyle(el, css){
if(window.getComputedStyle) return getComputedStyle(el, '')[css];
if(el.currentStyle) return el.currentStyle[css];
}
alert(getStyle(document.getElementById('bar'),'borderTopWidth'));
注意 - css 定义需要样式和边框的宽度才能具有计算的宽度(并且在计算其尺寸时不能将其设置为显示:none...
相关文章:
- 将函数的上下文应用于javascript变量
- keyup事件处理程序更改焦点不适用于快速键入
- JQueryhide()不适用于Mozzilla,但适用于Chrome
- JavaScript数组排序(函数)用于对表行进行排序,而不是排序
- PHP中的setcookie仅适用于localhost
- 包括用于facebook评论框的JavaScript SDK
- 如何检测用于WebGL的专用或集成显卡
- ng更改事件不适用于Dropdown
- 用于搜索的聚合物嵌套绑定
- jQuery表单添加不适用于下拉列表
- Rails/JSON:如何将JSON用于jquery UI自动完成表单
- JS编译器/包管理器,用于版本控制
- 如果我在javascript中输入无效的电子邮件或空白,如何显示特定的文本框边框红色
- 将CSS应用于printWindow.print();在Javascript中
- getComputedStyle 或 currentStyle 用于边框左宽
- Javascript切换图像边框在Firefox中有效,但不适用于IE
- 用于IE8的弯曲边框CSS
- tr上的边框颜色不适用于IE-7
- 将边框应用于SlidesJS框架无效
- CSS不适用于IE-边框样式更改