未捕获的TypeError:无法读取null的属性'style' - JS错误

use*_*791 2 javascript null jquery styles document

我从我的控制台收到一个javascript错误:

未捕获的TypeError:无法读取null的属性'style'

有谁知道什么是错的?

代码(JS):

<script>
    function select()
    {
        document.getElementById('#iframetest').style.display='block';
    }

</script>
Run Code Online (Sandbox Code Playgroud)

代码(HTML):

<iframe src="localhost/createaclass" id="iframetest"></iframe>

<div class="b" onclick="select()">
Run Code Online (Sandbox Code Playgroud)

Bho*_*yar 9

不要将哈希放在id(#)中:

document.getElementById('iframetest')
Run Code Online (Sandbox Code Playgroud)

根据你的评论,你可以这样做:

function select()
{
   document.getElementById('iframetest').style.display = 'block' ? 'none' : 'block';
}
Run Code Online (Sandbox Code Playgroud)