本站首页    管理页面    写新日志    退出


«September 2025»
123456
78910111213
14151617181920
21222324252627
282930


公告
 本博客在此声明所有文章均为转摘,只做资料收集使用。

我的分类(专题)

日志更新

最新评论

留言板

链接

Blog信息
blog名称:
日志总数:1304
评论数量:2242
留言数量:5
访问次数:7620427
建立时间:2006年5月29日




[Prototype(Ajax)]Prototype.js 筆記
软件技术

lhwork 发表于 2006/8/31 10:46:38

目錄 [隱藏] 1 參考文件2 好用的3 幫它打上類固醇(Like Ruby)4 Class5 事件 [編輯]參考文件 prototype JavaScript Framework Developer Notes for prototype.js script.aculo.us's prototype library documentation Quick Guide to Prototype Overview of the Prototype Javascript Library Prototype Slides - relevance [編輯]好用的 $('myDiv') it's better than document.getElementById() $F('userName') it returns the value of any field input control [編輯]幫它打上類固醇(Like Ruby) Loop Ruby style var simpsons = ['Homer', 'Marge', 'Lisa', 'Bart', 'Meg'];simpsons.each( function(familyMember){ alert(familyMember); }); The Object extensiton of inspect() is there. The Enumerable and Array references for all the available functions, ex: find & findAll... var listBox = $('lstEmployees')var options = listBox.getElementsByTagName('option');options = $A(options);var opt = options.find( function(employee){ return (employee.value == emp_id);});paragraph = $(paragraph);var links = $A(paragraph.getElementsByTagName('a'));//find links that do not start with 'http'var localLinks = links.findAll( function(link){ var start = link.href.substring(0,4); return start !='http';});//now the link textsvar texts = localLinks.pluck('innerHTML');//get them in a single stringvar result = texts.inspect();alert(result); [編輯]Class Class 宣告, options 是一個 map, 可以預設一些設定及讓 programmer 控制 var Klass = Class.create();Klass.prototype = { initialize: function(elem, options) { this.options = Object.extend({ speed: 0.1, delay: 0.0 }, options || {}); this.elem = $(elem); }, method1: function() { }, method2: function() { }} Class 實例 var kls = new Klass('id');var kls = new Klass('id', {speed: 0.5}); 繼承(It's not good now) SubKlass = Class.create();SubKlass.prototype = Object.extend(new Klass, { initialize: function(ele, options) { }, method1: function() { }, method2: function() { }}); [編輯]事件 bind, the returned function will have the same arguments as the original one. bindAsEventListener, the returned function will have the current event object as its argument. Event.observe 例如: this.form.onsubmit = this.onSubmit.bindAsEventListener(this);onSubmit: function(event) { var elem = Event.element(event);}, Event.observe(element, 'load', function(event){ //... });Event.observe(element, 'load', this.onXXX.bind(this)); Event.stopObserving(...); Event.stop(e); link titleInsert non-formatted text here==Ajax== new Ajax.Request(this.validateAction, { method: 'ge--~~~~t', parameters: e.name + "=" + e.value, onSuccess: (fun----ction(req) { th[http://www.example.com link title][[Link title]]is.reportValidation(e, req.responseText); }).bind(this), onFailure: function(req) {alert(req.responseText)}, onException: function(t,e) {alert(e);}});


阅读全文(1721) | 回复(0) | 编辑 | 精华
 



发表评论:
昵称:
密码:
主页:
标题:
验证码:  (不区分大小写,请仔细填写,输错需重写评论内容!)



站点首页 | 联系我们 | 博客注册 | 博客登陆

Sponsored By W3CHINA
W3CHINA Blog 0.8 Processed in 0.047 second(s), page refreshed 144787070 times.
《全国人大常委会关于维护互联网安全的决定》  《计算机信息网络国际联网安全保护管理办法》
苏ICP备05006046号