以下整理 prototype.js 中常用的函數與其說明、範例。
Element.toggle('div1','div2')Element.hide('div1','div2')Element.show('div1','div2')Element.remove('div1','div2')Element.getHeight('div1')Toggle.display('div1','div2')Insertion.Before('div1','my content')Insertion.After('div1','my content')Insertion.Top('div1','this is a text')Insertion.Bottom('div1','this is a text')new PeriodicalExecutor(test, 1),其中 test 是 JavaScript 函數,1 是頻率(1 秒)。$('div1')Field.clear('textField1')Field.focus('select1')alert(Field.present('textField1'))Field.select('textField1')Field.activate('textField1')Form.disable('form1')(這個好像不太 work)Form.focusFirstElement('form1')Form.reset('form1')Form.Element.getValue('text1')Form.Element.serialize('text1')$F('text1')Effect.Highlight('text1')Effect.Scale('text1', 200),這裡 200 = 200%,也就是兩倍。Effect.Squish('text1')Effect.Puff('text1')Ajax.Request('https://server/s.php')Ajax.Updater('text1','https://server/s.php')prototype.js 為每個主要的類都做了封裝,使用起來很方便。要產生特定效果,只要用 new Class.function(<argument>) 即可。例如:
<div id="div1"><a href="#">Click Me</a></div> <div id="div2">Hello!</div>
當你點擊 Click Me 時,div2 就會交替隱藏或顯示。注意,你可以給 toggle 加上任意多個參數,例如 Element.toggle('div2','div3','div4',...)。