这是功能:
function lastmenuborder() {
var articleparent = document.getElementById('article').parentNode;
var articlestyle = window.getComputedStyle(articleparent,null).getPropertyValue('borderRadius');
alert (articlestyle);
}
我没有得到任何价值,但父节点的css是:
div#mainbody div.placeholder {
border-radius: 3px;
}
我需要更改什么才能返回“3px”?所有人都非常感谢;我仍然是JavaScript的新手。
答案 0 :(得分:10)
对于getPropertyValue()
,您使用连字符而不是camelCase。
这适用于Chrome ...
.getPropertyValue('border-radius');
但Firefox似乎需要使用这种语法的特定角落......
.getPropertyValue('border-top-left-radius');
答案 1 :(得分:0)
getComputedStyle ,以解决此问题:
if (!window.getComputedStyle) {
window.getComputedStyle = function(el, pseudo) {
this.el = el;
this.getPropertyValue = function(prop) {
var re = /(\-([a-z]){1})/g;
if (prop == 'float') prop = 'styleFloat';
if (re.test(prop)) {
prop = prop.replace(re, function () {
return arguments[2].toUpperCase();
});
}
return el.currentStyle[prop] ? el.currentStyle[prop] : null;
}
return this;
}
}
var elem = window.getComputedStyle(document.getElementById('test'), "");
alert(elem.getPropertyValue("borderRadius"));