zoukankan      html  css  js  c++  java
  • js 对象

    <html>
    <head>
    <title>范例4-25</title>
    </head>
    <body>
    <script language="javascript">
    <!--
      var student = new Object();       // 创建一个对象表示学生
      student.name = "Tom";             // 为学生对象添加“名字”属性
      student.age = 20;                 // 添加“年龄”属性
      student.sex = "男";               // 添加性别属性
      document.write( "<li>" + student["name"] + ":" + student["sex"] + " " + student["age"] );    // 输出学生的三个属性
      delete student.age;                                                                           // 删除学生的“年龄”属性
      document.write( "<br>删除了age属性<br><li>" + student["name"] + ":" + student["sex"] + " " + student["age"] );   // 再次输出全部属性作对比
    --> 
    </script>
    </body>
    </html>

    out:

      • Tom:男 20
        删除了age属性
      • Tom:男 undefined
    <html>
    <head>
    <title>范例4-26</title>
    </head>
    <body>
    <script language="javascript">
    <!--
        function showStudentInfo()
        {
            // 输出this指针指向的对象的name、age成员
            document.write( "<li>" + this.name + " " + this.age + "<br>" );
        }
        function Student( _name, _age )         // 定义Student类的构造函数
        {
            this.name = _name;
            this.age = _age;
        }
        var stu1 = new Student( "Tom", 20 );    // 创建两个学生类实例
        var stu2 = new Student( "Lily", 21 );
        showStudentInfo.call( stu1 );           // 分别以stu1、stu2作为上下文调用showStudentInfo函数
        showStudentInfo.call( stu2 );
    --> 
    </script>
    </body>
    </html>

    out:

    • Tom 20
    • Lily 21
  • 相关阅读:
    python 集合
    jQuery选择器
    hdu 5747 Aaronson
    hdu 2049 不容易系列之(4)——考新郎
    hdu 2048 神、上帝以及老天爷
    hdu 2045 不容易系列之(3)—— LELE的RPG难题
    hdu 2047 阿牛的EOF牛肉串
    hdu 2046 骨牌铺方格
    hdu 2050 折线分割平面
    hdu 2044 一只小蜜蜂
  • 原文地址:https://www.cnblogs.com/huodaihao/p/7309430.html
Copyright © 2011-2022 走看看