首页 > 解决方案 > 从 CSS 样式 Javascript 中获取元素

问题描述

我试图在警报窗口中获取我的类 kreis 属性的值,但获取背景:#00FF00 和高度:20px,警报窗口不打印任何内容,我不知道为什么。提前感谢您的帮助!特此代码:

<style>
#kreis{
    width:200px;
    height: 200px;
    border-radius:50%;
    background:#00FF00;
    top: 300px;
    text-align:center;
    display: inline-block;
    cursor:pointer;

}

</style>

<div onclick="Ball()" id="kreis"></div>

<script>
    function Ball() {
        alert("Hola");
        var style=document.getElementById("kreis").style;
        alert(style);
        alert(style.background);
        var color=style.height;
        alert(color); 
</script>

标签: javascripthtmlcss

解决方案


推荐阅读