当 'border-style' 为 'none' 时,用 jQuery 得到 'border-width'
Get 'border-width' with jQuery when 'border-style' is 'none'
我需要帮助解决这个简单的问题。我正在尝试获取元素的边框宽度,但 jQuery 总是检索“0px”,有没有办法获取 'border-width'?
$('div').css({
'border-width': '6px',
'border-style': 'solid'
});
$('div').css({
'color': 'rgb(207, 38, 38)'
});
$('div').css({
'border-style': 'none'
});
console.log($('div').css('borderWidth')); //Here is the problem I need the value to be '6px'
div {
width: 100px;
height: 40px;
background-color: yellow;
position: relative;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>element</div>
编辑:
我正在使用googlechrome,会不会是浏览器的bug?
提前致谢。
编辑 2:
我需要 jQuery 解决方案 而不是 VanillaJS
不用jQuery也可以。
var element = document.getElementsByTagName('div')[0];
console.log(element.style.borderWidth);
我需要帮助解决这个简单的问题。我正在尝试获取元素的边框宽度,但 jQuery 总是检索“0px”,有没有办法获取 'border-width'?
$('div').css({
'border-width': '6px',
'border-style': 'solid'
});
$('div').css({
'color': 'rgb(207, 38, 38)'
});
$('div').css({
'border-style': 'none'
});
console.log($('div').css('borderWidth')); //Here is the problem I need the value to be '6px'
div {
width: 100px;
height: 40px;
background-color: yellow;
position: relative;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>element</div>
编辑:
我正在使用googlechrome,会不会是浏览器的bug?
提前致谢。
编辑 2: 我需要 jQuery 解决方案 而不是 VanillaJS
不用jQuery也可以。
var element = document.getElementsByTagName('div')[0];
console.log(element.style.borderWidth);