Linux中国  设为主页
 收藏本站
 
当前位置: > 首页 ->网站设计 ->AJAX教程 ->prototype.js 1.4 原代码阅读
  相关分类: 
AJAX教程
CSS/CSS2
Dreamweaver
Fireworks
Flash
HTML/DHTML
JavaScript
Phososhop
网页制作
  站内搜索: 
热门文章排行
热门文章排行 Ajax实现分页查询(06-04)
prototype.js 1.4 原代码阅读(04-24)
使用AjaxPro开发四级无刷新联动下拉(06-04)
在Struts应用中使用Ajax(04-24)
Ajax:拥抱JSON,让XML走开(04-24)
精采文章排行
精采文章排行 使用AjaxPro开发四级无刷新联动下拉(06-04)
微软Asp.net Ajax 1.0的AutoComplete(06-04)
Ajax实现分页查询(06-04)
Ajax实现不刷屏的前提下实现页面定时(06-04)
Ajax程序设计入门(06-04)
  ·微软Asp.net Ajax 1.0的AutoComplete控件·Ajax实现分页查询·Ajax实现不刷屏的前提下实现页面定时刷新·Ajax程序设计入门·微软的Ajax库客户端Bug总结·利用AJAX和ASP.NET实现简单聊天室 ·利用AJAX技术实现网页无刷新进度条显示·Ajax联动下拉框的实现例子·AJAX如何与后台交互

prototype.js 1.4 原代码阅读

作者:Webmaster   来源:Linux-cn.com   点击:   日期:2007-04-24 [收藏] [投稿]

  IE是否经常中毒?推荐您


    this.frequency = frequency;
    this.element   = $(element);
    this.callback  = callback;

    this.lastValue = this.getValue();
    this.registerCallback();
  },

  registerCallback: function() {
    setInterval(this.onTimerEvent.bind(this), this.frequency * 1000);
  },

  onTimerEvent: function() {
    var value = this.getValue();
    if (this.lastValue != value) {
      this.callback(this.element, value);
      this.lastValue = value;
    }
  }
}

Form.Element.Observer = Class.create();
Form.Element.Observer.prototype = Object.extend(new Abstract.TimedObserver(), {
  getValue: function() {
    return Form.Element.getValue(this.element);
  }
});

Form.Observer = Class.create();
Form.Observer.prototype = Object.extend(new Abstract.TimedObserver(), {
  getValue: function() {
    return Form.serialize(this.element);
  }
});

/*--------------------------------------------------------------------------*/

Abstract.EventObserver = function() {}
Abstract.EventObserver.prototype = {
  initialize: function(element, callback) {
    this.element  = $(element);
    this.callback = callback;

    this.lastValue = this.getValue();
    if (this.element.tagName.toLowerCase() == 'form')
      this.registerFormCallbacks();
    else
      this.registerCallback(this.element);
  },

  onElementEvent: function() {
    var value = this.getValue();
    if (this.lastValue != value) {
      this.callback(this.element, value);
      this.lastValue = value;
    }
  },

  registerFormCallbacks: function() {
    var elements = Form.getElements(this.element);
    for (var i = 0; i < elements.length; i++)
      this.registerCallback(elements[i]);
  },

  registerCallback: function(element) {
    if (element.type) {
      switch (element.type.toLowerCase()) {
        case 'checkbox':
        case 'radio':
          Event.observe(element, 'click', this.onElementEvent.bind(this));
          break;
        case 'password':
        case 'text':
        case 'textarea':
        case 'select-one':
        case 'select-multiple':
          Event.observe(element, 'change', this.onElementEvent.bind(this));



 如果您对本文有任何疑问或者建议,请到讨论区发表您的意见: >> 论坛入口 <<

上一页 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 2324 25 26 27 28 29 30 31 下一页

上一篇:prototype.js1.4 版开发者手册   下一篇:prototype.js常用函数及其用法
文章评论】 【收藏本文】 【推荐好友】 【打印本文】 【我要投稿】 【论坛讨论

   相关文章:
·使用AjaxPro开发四级无刷新联动下拉框

   文章评论:(1条)
  
 请留名: 匿名评论   点击查看所有评论 论坛讨论
 

 声明:刊登此文章是为了传递更多信息,文章内容仅供参考,转载请注明出处。