美文网首页
利用传参取行间样式

利用传参取行间样式

作者: 乍暖还寒2002 | 来源:发表于2017-10-07 08:24 被阅读0次

//style 只能取到行间样式

function getStyle(obj,name) {

if (obj.currentStyle) {//判断真假

return onj.currentStyle.name;

} else {

return getComputedStyle(obj,false)[name];

}

}

var div1 = document.getElementById('div1');

// if (div1.currentStyle) {

// //兼容ie

// alert(div1.currentStyle.width);

// } else {

// //兼容ff

// alert(getComputedStyle(div1, false).width);

// }

alert(getStyle(div1,'width'));

alert(getStyle(div1,'backgroundColor'));

//不能取复合样式,  例如:background  border

相关文章

网友评论

      本文标题:利用传参取行间样式

      本文链接:https://www.haomeiwen.com/subject/jdidyxtx.html