javascript - Why are the margin values ​​different between using native js to get the body and using jquery to get the body?
怪我咯
怪我咯 2017-07-05 10:42:07
0
2
867
console.log(document.getElementsByTagName("body")[0].style.margin)  空
        console.log($("body").css("margin"))  8px
怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(2)
黄舟

You can try to get width and the like, and the result will be ''

Because XXX.style.XXX extracts industry attributes

Because what you set through XXX.style.XXX is also an inline attribute, so you can get it this time

Then how to take out the attributes set with css

getComputedStyle(element).margin
迷茫

The two obtained tags <body> are the same, but the first attribute is overwritten and is empty, and the second one is not overwritten and is 8px.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template