我把这个样式应用到一个 div 上
div#content {
border: 1px solid skyblue;
}
我希望能够提醒边框的宽度,我试过这个:
window.alert( document.getElementById( "content" ).style.borderWidth );
我听说这取决于浏览器也许你能帮我 我正在使用 Firefox 18
最佳答案
请尝试以下 javascript:
alert($("#content").css("border-left-width")); //using jquery.
或
alert(getComputedStyle(document.getElementById('content'),null).getPropertyValue('border-left-width'));//without jquery.
getComputedStyle
(元素,伪)
element:要为其设置样式的元素
伪:伪选择器,如“悬停”,如果不需要则为 null。
引用链接:http://javascript.info/tutorial/styles-and-classes-getcomputedstyle
关于javascript - 使用纯 javascript 从 div 获取边框宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14681002/