• JavaScript函数的调用


    今天练习javascript中页面的onload和onunload事件时,总是没有触发,但是又没有错误。

    后来检查发现在onload与onunload事件所对应的方法调用时,没有打括号,造成的。

    错误的代码:

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    <script language="JavaScript">
    //alert("这是第一个JavaScript例子。");
    //alert("欢迎你进入JavaScript世界!");
    //alert("今后我们将共同学习JavaScript知识!");

    //document.write("这是赛迪网互动学校");
    //document.close();

    function loadfrom(){
     alert("加载页面!");
     }
     
    function unloadfrom(){
     alert("关闭页面!");
     }


    </script>
    </head>

    <body  OnLoad="loadfrom" OnUnload="unloadfrom">
    <p>&nbsp;</p>
    </body>
    </html>


    正确的代码:

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    <script language="JavaScript">
    //alert("这是第一个JavaScript例子。");
    //alert("欢迎你进入JavaScript世界!");
    //alert("今后我们将共同学习JavaScript知识!");

    //document.write("这是赛迪网互动学校");
    //document.close();

    function loadfrom(){
     alert("加载页面!");
     }
     
    function unloadfrom(){
     alert("关闭页面!");
     }


    </script>
    </head>

    <body  OnLoad="loadfrom()" OnUnload="unloadfrom()">
    <p>&nbsp;</p>
    </body>
    </html>


     

  • 相关阅读:
    linq 读取xml
    c# 定时器 自动执行
    如何在一个人输入框中只输入数字
    如何去掉滚动条,
    如何计算任意值之间的随机数呢
    【P2387】魔法森林(SPFA非正解)
    【Luogu】P3203弹飞绵羊(分块)
    【Luogu】P3396哈希冲突(根号算法)
    【Luogu】P2801教主的魔法(分块)
    【Luogu】P3155叶子的染色(树形DP)
  • 原文地址:https://www.cnblogs.com/zqonline/p/912404.html
Copyright © 2020-2023  润新知