在正文结尾之前调用JavaScript函数

在正文结尾之前调用JavaScript函数,javascript,html,Javascript,Html,如何在HTML页面正文结束之前调用JavaScript函数? <html> <head> <script...> function helloWorld() { alert('Hello world!'); } </script> </head> <body> ...some content... <script...> helloWorld();

如何在HTML页面正文结束之前调用JavaScript函数?


<html>
<head>
<script...>
    function helloWorld() {
        alert('Hello world!');
    }
</script>
</head>
<body>
...some content...
    <script...>
        helloWorld();
    </script>
</body>
</html>
函数helloWorld(){ 警惕(“你好,世界!”); } …一些内容。。。 helloWorld();

函数helloWorld(){
警惕(“你好,世界!”);
}
…一些内容。。。
helloWorld();

您可以在其中放置一个
块,如下所示:

  <script type="text/javascript">
    myFunction();
  </script>
</body>

myFunction();

另外,如果您正在使用某种框架,大多数框架都有处理程序,用于DOM就绪时,或者您可以使用最适合您的情况的任何处理程序。

您可以在其中放置一个
块,如下所示:

  <script type="text/javascript">
    myFunction();
  </script>
</body>

myFunction();
此外,如果您使用的是某种框架,大多数框架都有处理程序,用于DOM准备就绪时,或者您可以使用最适合您的情况的任何处理程序