//定义一个类
function TestClass(name)
{
    //定义一个属性,并设置默认值
    this.Name = name || "jxh";

    //定义一个方法
    this.GetName = function()
    {
        return this.Name;
    }
}

<script language = "javascript">
 
    var testClass; //声明一个类

    function Page_Load()
    {
        //初始化类,2种方式
  
        //testClass = new TestClass();
        //testClass.Name = "jxhwei";
        testClass = new TestClass("jxhwei");
    }

    function CLick_Event()
    {
        var name = testClass.GetName(); //调用类的方法
        //var name = testClass.Name;

        alert(name);
    }
</script>

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-01
  • 2022-02-08
  • 2021-11-08
猜你喜欢
  • 2022-12-23
  • 2022-01-08
  • 2021-10-09
  • 2022-02-06
  • 2021-08-10
  • 2021-07-25
  • 2022-01-05
相关资源
相似解决方案