我从控制台收到一个 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';
}
关于javascript - 未捕获的类型错误 : Cannot read property 'style' of null - JS error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25235389/