未捕获的TypeError: Cannot read property 'style'null - JS
Uncaught TypeError: Cannot read property 'style' of null - JS error
我得到一个javascript错误从我的控制台读取:
Uncaught TypeError: Cannot read property 'style' of null
有谁知道怎么回事吗?
代码(JS):<script>
function select()
{
document.getElementById('#iframetest').style.display='block';
}
</script>
代码(HTML): <iframe src="localhost/createaclass" id="iframetest"></iframe>
<div class="b" onclick="select()">
不要在id (#):
document.getElementById('iframetest')
根据你的评论,你可以这样做:
function select()
{
document.getElementById('iframetest').style.display = 'block' ? 'none' : 'block';
}
将JS移到HTML下面。
<iframe src="localhost/createaclass" id="iframetest"></iframe>
<div class="b" onclick="select()">
<script>
function select()
{
document.getElementById('#iframetest').style.display='block';
}
</script>
也许回答太晚了。但你的选择器返回null因为在
这一行document.getElementById('#iframetest').style.display='block';
你需要把它改成:
document.getElementById('iframetest').style.display='block';
当你指定getElementById时,你的JS将直接转到id为'iframetest'的元素。不需要'#'
如果您正在使用jquery,请尝试此操作。这是工作。
$('.b').click(function(){
$('#iframetest').hide();
});
<iframe src="localhost/createaclass" id="iframetest"></iframe>
<div class="b">selectDiv</div>
参见jsfiddle link http://jsfiddle.net/17duuxcm/5/
相关文章:
- 数组在递归方法中设置为null
- javascript无法读取属性'style'为null
- 无法在Chrome的Javascript控制台中读取null的属性“style”
- JavaScript TypeError:无法读取 null 的属性“style”
- 未捕获的类型错误:无法读取属性'style'为null
- 如何修复未捕获的类型错误:无法读取属性'style'为null
- 未捕获的类型错误:无法读取属性'style'为null
- 0.style为null或不是aobject
- HTML已创建,但style = null
- 未捕获的TypeError: Cannot read property 'style'null - JS
- TypeError: Cannot read property 'style' of null (Jav
- Webview:无法读取property 'style'null +意外标识符
- 未捕获类型错误:无法读取属性'style'null"
- TypeError: null不是对象(计算'document.getElementById(x).style&
- 不能读取属性'style'动态HTML代码中的null
- 未捕获的类型错误:无法读取属性'style'为null
- 道场'TypeError:无法读取属性'style'为null的'发送xhrPost请求
- Simon.js:未捕获类型错误:无法读取属性'style'为null
- JS 类型错误:无法读取 null 的属性“style”
- TypeError: Cannot read property 'style' of null in j