未捕获的类型错误:无法读取属性'style'为null
Uncaught TypeError : Cannot read property 'style' of null
所以我试图改变一个盒子的背景,但我得到了。我需要你的答案,而不是我在这页上读到的所有答案,没有一个不能解决我的问题。我认为这是因为我是一个编程新手。这是代码:
<button onclick="changeBG('box1','#F0F');">Magenta</button>
<div id="box1"> content in box1</div>
<style type="text/css">
div#box1{
background-color: #9dceff;
width:400px;
height:200px;
}
</style>
<script type="text/javascript">
function changeBG(el,color){
var elem = document.getElementById('el');
elem.style.transition ="background 1.0s linear 0s ";
elem.style.background =color;
}
</script>
提前感谢
如果使用
var elem = document.getElementById('el');
CCD_ 1将是具有CCD_ 2的元素。
您应该使用以下内容:
var elem = document.getElementById(el);
如果您希望elem
是them元素,并且el
变量中的字符串具有id
。
相关文章:
- 为什么我可以'不要使用xx[this.index].style.display?它's说“;无法读取属性
- 如何让firefox使用style['attribute name']=设置样式属性
- "无法获取属性'的值;style'"当试图在IE中更改样式时
- 如何使主体采用等同于 style=“background-color: returnBlue()” 的样式属性,其中 r
- javascript无法读取属性'style'为null
- 滚动字幕未捕获类型错误:无法读取属性'style'的未定义
- 如何从javascript访问html的STYLE标记中的class属性
- 如何在IE8上使用setAttribute而不是使用style.cssText来更改样式属性
- 无法在Chrome的Javascript控制台中读取null的属性“style”
- 如何使用 .querySelectorAll 选择器定位 .style 属性
- 为包含 HTML 标记的字符串中的元素设置 Style 属性
- JavaScript TypeError:无法读取 null 的属性“style”
- DOM “style” 属性与实际 CSS 样式之间的关系
- document.getElementsByTagName:无法读取未定义的属性“style”
- 未捕获的类型错误:无法读取属性'style'为null
- 是否可以通过nightwatch.js设置元素的Style属性的值?如果是,那么如何
- 未捕获类型错误:无法读取属性'style'null"
- 不能读取属性'style'动态HTML代码中的null
- JS 类型错误:无法读取 null 的属性“style”
- 0x800a138f - JavaScript运行时错误:无法获取属性'style'未定义或空引用的