使用纯javascript从div获取边框宽度 [英] Get border width from a div with plain javascript
问题描述
我将这种风格应用于div
div#content {
border:1px solid blue blueblue;
}
我希望能够提醒边框的宽度,我有试用这个:
window.alert(document.getElementById(content).style.borderWidth);
听说取决于浏览器,也许你可以帮我
我正在使用Firefox 18
请尝试以下javascript:
警报($( #内容)的CSS( 左边框宽度)。); //使用jquery。
或
alert(getComputedStyle(document.getElementById('content'),null).getPropertyValue('border-left-width')); //没有jquery。
getComputedStyle
(元素,伪)
元素:获取样式的元素
pseudo:伪选择器,如'hover';如果不需要,则为null。
参考链接: http:/ /javascript.info/tutorial/styles-and-classes-getcomputedstyle
I got this style applied to a div
div#content {
border: 1px solid skyblue;
}
and i want to be able to alert the width of the border, I have tried with this:
window.alert( document.getElementById( "content" ).style.borderWidth );
I heard that depends of the browser maybe you can help me I'm using Firefox 18
Please try the below javascript:
alert($("#content").css("border-left-width")); //using jquery.
or
alert(getComputedStyle(document.getElementById('content'),null).getPropertyValue('border-left-width'));//without jquery.
getComputedStyle
(element, pseudo)
element:The element to get a styling for
pseudo:A pseudo-selector like ‘hover’ or null if not needed.
Reference link: http://javascript.info/tutorial/styles-and-classes-getcomputedstyle
这篇关于使用纯javascript从div获取边框宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!