Reading CSS value using JavaScript

前端 未结 7 685
梦毁少年i
梦毁少年i 2021-01-28 17:43

This works:

相关标签:
7条回答
  • 2021-01-28 18:24

    In InternetExplorer you can use .currentStyle instead of .style. In other browsers, you can use the getComputedStyle mechanism.

    var yourElement = document.getElementById('whatever');
    var theStyle = window.getComputedStyle(yourElement);
    

    You can then call .getPropertyValue() on the returned style object to find the CSS properties you're interested in.

    0 讨论(0)
提交回复
热议问题