javascript - 从 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>
解决方案
推荐阅读
- r - 如何从 RStudio 的查看器中保存高分辨率 .png?
- spring-boot - Spring Cloud AWS 自动配置凭证
- python - 读取csv文件时如何排除字典字典中的重复键?
- java - 在线程中使用 Javafx TimeLine
- javascript - 停止单击父级上的子级调用方法 - React/JavaScript
- docker - Docker windows 保存到文件系统
- pandas - 作为数据框中对象的2个日期之间的差异
- html - div之间不需要的空白
- javascript - 切换时 React-select 显示键盘
- javascript - 箭头功能被跳过