The example of this article describes the way JS gets inline style. Share to everyone for your reference. The implementation methods are as follows:
Copy Code code as follows:
<! DOCTYPE html>
<meta charset= "UTF-8" >
<meta name= "viewport" content= "width=device-width,target-densitydpi=high-dpi,initial-scale=1.0, minimum-scale= 1.0, maximum-scale=1.0, User-scalable=no "/>
<title>javascript Get inline style </title>
<style>
#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;
}
</style>
<body>
<div id= "box" ></div>
</body>
<script>
Get inline style elements
function GetStyle (obj, attr)
{
if (window.getComputedStyle) {
return getComputedStyle (obj, null) [attr];
}else{
return obj.currentstyle[attr];
}
}
Get Object
function $ (ID) {
return document.getElementById (ID);
}
var box = $ (' box ');
Print style
Alert (GetStyle (box, ' background-position '));
</script>
I hope this article will help you with your JavaScript programming.