Uncaught ReferenceError: loaderOff is not defined at HTMLIFrameElement.onload

Uncaught ReferenceError: loaderOff is not defined at HTMLIFrameElement.onload

我环顾四周,但没有任何帮助。 这很简单。

<html>
<head>
</head>
<body>
...
<iframe onload="loaderOff()" src="" frameborder="0"></iframe>
...
...
<script>

  function loaderOn(){
    var loader = document.getElementById("loader");
    var main = document.getElementById("main");
    loader.classList.remove('hide');
    main.classList.add("blur");
  }

  function loaderOff(){
    var loader = document.getElementById("loader");
    var main = document.getElementById("main");
    loader.classList.add('hide');
    main.classList.remove("blur");
  }

  ...
  ...

</script>
</body>
</html>

但我明白了,

Uncaught ReferenceError: loaderOff is not defined at HTMLIFrameElement.onload

虽然功能正常,但是控制台报错; 有帮助吗?

@Teemu 评论是对的,我只是尝试将 <script> 改成 <head> 并且成功了。