当前位置:首页 > JavaScript

jquery.objectize JavaScript 面向对象编程

canca16年前 (2011-06-28)JavaScript504

demo.html

<html>
 <head>
  <title>JQuery 面向对象编程插件</title>
  <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
  <style type="text/css">
   .userName{
    color:#00f;
   }
  </style>
  <script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
  <script type="text/javascript" src="js/jquery.objectize.js"></script>
  <script type="text/javascript">
   $.include("example.io.Base"); //导入example/io/Base.js
   $.include("example.io.File"); //导入example/io/File.js
   $(function(){
    //定义类方法1:
 /*   var a = $.Class('example.io.Base').New("a","b");
    var b = $.Class('example.io.File').New("c","d");

    //定义类方法2:
    $.Objectize.namespaces();
    var a = example.io.Base.New("a", "b");
    var b = example.io.File.New("c", "d");
     
    //调用类方法
    b.showMsg();
    alert(b.doSomething());

    //判断类类型
    alert(b.is("example.io.Base"));
 */
    $.Class("user.form.Div",{
     Div : function(clsName){
      this.object().attr("class",clsName);
     },
     templet : '<div>${userName}</div>',
     _o : null,
     object : function(){
      if(this._o == null){
       this._o = $(this.templet);
      }
      return this._o;
     },setUserName : function(userName){
      this.object().html(userName);
     }
    });
    $.Class("user.form.UserName","user.form.Div",{
     UserName : function(clsName,data){
      this.Div(clsName);
      this.object().html(data);
     },writeTo : function(elem){
      $(elem).append(this.object());
     }
    });

    var userName = $.Class("user.form.UserName").New("userName","Mr.CT");
    userName.object().click(function(){
     alert($(this).html());
    }).css({"cursor" : "pointer"}).hover(function(){
     $(this).css("color","#ff0000");
    },function(){
     $(this).css("color","#0000ff");
    });
    $(userForm).append(userName.object());
   });
  </script>
 </head>
 <body>
  <div id="userForm">
   
  </div>
 </body>
</html>

 

Base.js

$.Class('example.io.Base', {
 x : 30,
 y : 20,
 watch: function(people){
  return people + "看电视!";
 },
 Base : function( a, b ) {
  alert("Base: " + a+","+b);
 }
});

 

File.js

$.Class('example.io.File','example.io.Base',{
 File : function( a, b ) {
  this.Base(a, b);
 },
 showMsg:function(){
  alert("X:" + this.x + " Y: " + this.y);
 },
 doSomething:function(){
  return this.watch("Mr.CT");
 }
});

扫描二维码推送至手机访问。

版权声明:本文由Ant.Master's Blog发布,如需转载请注明出处。

本文链接:https://iant.work/post/236.html

标签: JavaScript
分享给朋友:

“jquery.objectize JavaScript 面向对象编程” 的相关文章

《Dom Scripting》读书笔记

  《Dom Scripting》读书笔记 Canca         最近看了一本《Jeremy Keith: DOM Scripting, Web design with JavaScript and the DOM. Apr…

javascript MailTo 邮件技巧

调用email的方法 //<a href="mailto:talantlee@126.com">Email</a>window.location.href="mailto:talantlee@126.com";myform.action="mailto:talant…

javascript 弹出式窗体详解

1>window.prompt(text, value) 簡單的基與模態窗體的對話框,(返回你輸入)   var v=window.prompt("提示","請輸入你的名字")2>window.confirm(text,mess)  模態確認框(返回"是/否…

JavaScript 为网页添加快捷键

为网页添加快捷键即为网页添加onkeydown事件。 FireFox里获取键入键的ASCII码与IE获取是有些差别的。因为FF里没有Event对象。 但FF里事件触发方法中默认传送其事件对象。 即我们在JS里写该事件方法时,要多加一个参数。 例: <sc...…

JavaScript对粘贴板的全操作

<html>    <head>        <script language="javascript">function copy_clip(copyObjectName…

常用javascirpt脚本

1.让文字不停地滚动 <MARQUEE>滚动文字</MARQUEE> 2.记录并显示网页的最后修改时间 <script language=javascript> document.write("最后更新时间: " + document.lastModified + "")…

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。