Prototype实战教程----8.顶层对象

2016-02-19 16:36 0 1 收藏

生活已是百般艰难,为何不努力一点。下面图老师就给大家分享Prototype实战教程----8.顶层对象,希望可以让热爱学习的朋友们体会到设计的小小的乐趣。

【 tulaoshi.com - Web开发 】

htmlheadtitle顶层元素/titlescript src="prototype.js"/scriptscriptvar Person=Class.create();Person.prototype={  initialize:function(){},  name:'',  birthday:'',  age:'',  Show:function(){alert("This is "+this.name);}  };  function TestPerson()  {    var p=new Person();    p.name="Tom";    p.age=4;    p.birthday="1997-7-1";    p.Show();    };    var User=Class.create();        User.prototype={      initialize:function(){},      userid:'',      Report:function()      {        alert("UserID:"+this.userid+"  Name:"+this.name+"  Age:"+this.age+" Birthday:"+this.birthday);        }      };      Object.extend(User.prototype,Person.prototype);      function TestUser()  {    var user=new User();    user.name="Chou Fat";    user.age=4;    user.userid=2396    user.birthday="1997-7-1";      user.Show();    user.Report();      }    function ShowPrototypeInfo()    {alert(Prototype.Version+"  "+Prototype.ScriptFragment);      }      function TestInspect()    {var s="wanfangsoftcenter";      alert(Object.inspect(s));      }      //-------------------------------------------------------      function testFunctionBind()      {        var person=new Person();        person.name="Jerry";        person.age=4;      person.birthday="1997-7-1";         var user=new User();        user.name="Tom";        user.age=5;      user.userid=2396      user.birthday="1999-12-20";        var handler=user.Report.bind(person);        handler();        }        var Listener=new Class.create();        Listener.prototype={          initialize:function(btn,message)          {                  $(btn).onclick=this.showMessage.bindAsEventListener(message);            },            showMessage:function(message){              alert(message);              }          };                var listener=new Listener("testEventListener","点击!");      
    /script
body  input type=button value="ShowPrototypeInfo" onclick='return ShowPrototypeInfo();' /显示Prototype的基本信息brhrinput type=button value="TestPerson" onclick='return TestPerson();' /利用我们创建的Person类生成一个p对象 检测一下是否成功brinput type=button value="TestUser" onclick='return TestUser();' /User类继承Person类,生成一个User对象 检测一下是否成功brinput type=button value="TestInspect" onclick='return TestInspect();' /测试一下Object的Inspect方法brinput type=button value="testFunctionBind" onclick='return testFunctionBind();' /测试一下Object的FunctionBind方法brinput type=button value="testEventListener" id="testEventListener" /testEventListenerbrscript    var Listener=new Class.create();        Listener.prototype={          initialize:function(btn,message)          {         this.message=message;            $(btn).onclick=this.showMessage.bindAsEventListener(this);            },            showMessage:function(){              alert(this.message);              }          };                var listener=new Listener("testEventListener","点击!");

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com/webkaifa/)

  /script

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com/webkaifa/)

hrscriptfunction TimeExe(){  var timerExe=new PeriodicalExecuter(showTime,1);    }  function showTime()  {    var time =new Date();    var d = $('myDiv');    d.innerHTML=time;    }    /scriptdiv id="myDiv"pThis is a paragraph/pinput type="button" value=定时器测试 onclick="TimeExe();"br/divhrscript  function TestNumber()  {    var n=50;    var b=3;    alert(n.toColorPart());    alert(n.succ());alert(b.toPaddedString());   //b.times(alert());    }  /script  input type="button" value='Number测试' onclick="return TestNumber();"/br/body/html

来源:https://www.tulaoshi.com/n/20160219/1612519.html

延伸阅读
标签: Web开发
htmlheadscript src="prototype.js"/script script function testRemove() { Element.remove("mydiv3"); } function testReplace() { Element.replace("myDiv2",'img src="200607061129268fc45.jpg&qu...
标签: Web开发
!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"html head titleAjax/title script type="text/javascript" language="javascript" src="prototype.js" /script script type=&...
标签: Web开发
script src="prototype.js"/scriptinput type="button" id="btn" value="click" /input type="button" id="reg" value="register" /input type="button" id="unreg" value="unregister" /div id="status"/divscriptfunction ...
标签: Web开发
script src="prototype.js"/scriptform id="frm"div id="div1" input type="text" id="txt" name="txt" onchange="return alert('Now')"/ input type="text" id="txt2" name="txt2" / input type="button" ...
标签: Web开发
我想prototype.js里的ajax对象肯定吸引了不少人,大量封装好的ajax逻辑的类,对于我们这些初学者使用ajax有很大的帮助。 以下用一个我的具体使用例子来解释:效果看这里 1. Ajax.Request 你可以这样创建它 代码如下: var url = 'http://yoursever/your/your'; var pars = 'id=xxx'; var myAjax...

经验教程

210

收藏

69
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部