天天看點

prototype.js常用函數及其用法

< DOCTYPE html PUBLIC -WCDTD XHTML StrictEN httpwwwworgTRxhtmlDTDxhtml-strictdtd>

prototype.js常用函數及其用法

prototype.js常用函數: 函數名   解釋   舉例

Element.toggle   交替隐藏或顯示   Element.toggle(''div1'',''div2'')

Element.hide   隐藏   Element.hide(''div1'',''div2'')

Element.show 顯示   Element.show(''div1'',''div2'')

Element.remove   删除   Element.remove(''div1'',''div2'')

Element.getHeight   取得高度   Element.getHeight(''div1'')

Toggle.display   和Element.toggle相同   Toggle.display(''div1'',''div2'')

Insertion.Before   在DIV前插入文字   Insertion.Before(''div1'',''my content'')

Insertion.After   在DIV後插入文字   Insertion.After(''div1'',''my content'')

Insertion.Top   在DIV裡最前插入文字   Insertion.Top(''div1'',''this is a text'')

Insertion.Bottom   在DIV裡最後插入文字   Insertion.Bottom(''div1'',''this is a text'')

PeriodicalExecuter   以給定頻率調用一段JavaScript   PeridicalExecutor(test, 1)"這裡test是Javascript的函數,1是頻率(1秒).

$   取得一個DIV, 相當于getElementById()   $(''div1'')

Field.clear   清空一個輸入框   Field.clear(''textfield1'')

Field.focus 把 焦點集中在輸入框上   Field.focus(''select1'')

Field.present   判斷内容是否為空   alert(Field.present(''textfield1''))"

Field.select   選擇輸入框的内容   Field.select(''textfield1'')"

Field.activate   把 焦點集中在輸入框上并選擇輸入框的内容   Field.activate(''textfield1'')"

Form.serialize   把表格内容轉化成string   

Form.getElements   取得表格内容為數組形式   

Form.disable   disable表格所有内容   Form.disable(''form1'') (這個好象不work)

Form.focusFirstElement   把焦點集中在表格第一個元素上   Form.focusFirstElement(''form1'')

Form.reset   Reset表格 Form.reset(''form1'')

Form.Element.getValue   取得表格輸入框的值   Form.Element.getValue(''text1'')

Form.Element.serialize    把表格中輸入框内容轉化成string   Form.Element.serialize(''text1'')

$F   等同于Form.Element.getValue()   $F(''text1'')

Effect.Highlight   高亮特效.   Effect.Highlight(''text1'')

Effect.Fade   褪色特效   

Effect.Scale   放大縮小(百分比) Effect.Scale(''text1'', 200)

這裡200 = 200%, 即兩倍

Effect.Squish   消失特效.文字縮小後消失   Effect.Squish(''text1'')

Effect.Puff   消失特效.文字放大後消失   Effect.Puff(''text1'')

Effect.Appear   出現特效   

Effect.ContentZoom   ZOOM特效.   

Ajax.Request   傳送Ajax請求給伺服器   Ajax.Request(''http://server/s.php'')

Ajax.Updater   傳送Ajax請求給伺服器并用答複的結果更新指定的Container   Ajax.Updater(''text1'',''http://server/s.php'')

       基本用法:prototype.js給每個主要的類都分了一個Class,使用起來很友善.要産生特定的效果,隻要用new Class.function(<argument>)就可以了.例如:

<DIV id="div1"><a href="#" onclick="new Element.toggle('div2')">Click Me</a></DIV><DIV id="div2">Hello!</DIV>

       當點選Click Me的時候,div2就會交替隐藏或顯示.注意,你可以給toggle加上無限個parameter,比如Element.toggle(''div2'',''div3'',''div4'',...)

本文轉自 netcorner 部落格園部落格,原文連結:http://www.cnblogs.com/netcorner/archive/2007/07/02/2912341.html  ,如需轉載請自行聯系原作者

繼續閱讀