1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > html内敛样式background js获取内联样式的方法

html内敛样式background js获取内联样式的方法

时间:2019-12-26 11:02:19

相关推荐

html内敛样式background js获取内联样式的方法

javascript 获取内联样式

#box{

width:100px;

height:100px;

background-image:url(1.jpg);

background-size:140% 140%;

background-repeat:no-repeat;

border:20px solid rgba(0,0,0,.3);

background-clip:border-box;

background-position:-20px -20px;

}

//获取内联样式元素

function getStyle( obj , attr )

{

if ( window.getComputedStyle ) {

return getComputedStyle( obj , null )[attr];

}else{

return obj.currentStyle[attr];

}

}

//获取对象

function $(id){

return document.getElementById(id);

}

var box = $('box');

//打印样式

alert(getStyle(box , 'background-position'));

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。