- Prototype 教程
- Prototype - 主頁
- Prototype - 簡要概述
- Prototype - 有用功能
- Prototype - 實用方法
- Prototype - 元素物件
- Prototype - 數字處理
- Prototype - 字串處理
- Prototype - 陣列處理
- Prototype - 雜湊處理
- Prototype - 基本物件
- Prototype - 模版
- Prototype - 列舉
- Prototype - 事件處理
- Prototype - 表單管理
- Prototype - JSON 支援
- Prototype - AJAX 支援
- Prototype - 表達範圍
- Prototype - 定期執行
- Prototype 有用資源
- Prototype - 快速指南
- Prototype - 有用的資源
- Prototype - 討論
原型 - extend() 方法
此方法使用 Element.Methods 和 Element.Methods.Simulated 中包含的所有方法,擴充套件元素。
如果元素是輸入、文字區域或選擇標籤,也將使用 Form.Element.Methods 中的方法來擴充套件它。
如果它是表單標籤,還將使用 Form.Methods 來擴充套件它。
語法
element.extend();
返回值
無。
舉例
透過 Prototype 的自定義方法擴充套件元素,我們可以獲得語法糖和易用性,這是我們所有人夢寐以求的。例如,你可以使用擴充套件元素執行以下操作 −
element.update('hello world');
並且由於 Element 的大多數方法都會返回應用它們時的元素,因此你可以像這樣連結方法 −
element.update('hello world').addClassName('greeting');
請注意,Element 方法返回的所有元素都已擴充套件(是的,即使對於 Element.siblings 等方法,也會返回元素陣列),而 Prototype 的旗艦工具方法 $() 和 $$() 顯然也返回擴充套件元素。
prototype_element_object.htm
廣告