zoukankan      html  css  js  c++  java
  • 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>


     

  • 相关阅读:
    全文检索Lucene框架---分词器
    全文检索框架---Lucene
    Selenium问题总结
    monkey基本命令参数详解示例
    adb opendir failed ,permission denied
    VS调用python方法
    windows下使用pthread
    代码静态分析工具——splint的学习与使用
    三种方案在Windows系统下安装ubuntu双系统
    Ubuntu下载及安装
  • 原文地址:https://www.cnblogs.com/zqonline/p/912404.html
Copyright © 2011-2022 走看看