DIV CSS 佈局教程網

您现在的位置: DIV+CSS佈局教程網 >> 網頁腳本 >  >> JavaScript入門知識 >> AJAX入門 >> AJAX詳解
prototype.js 常用函數與用法速查
編輯:AJAX詳解     

以下整理 prototype.js 中常用的函數與其說明、範例。

Element 相關

  • 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 相關(插入內容)

  • Insertion.Before:在元素前插入文字。例:Insertion.Before('div1','my content')
  • Insertion.After:在元素後插入文字。例:Insertion.After('div1','my content')
  • Insertion.Top:在元素內容最前面插入文字。例:Insertion.Top('div1','this is a text')
  • Insertion.Bottom:在元素內容最後面插入文字。例:Insertion.Bottom('div1','this is a text')

其他工具

  • PeriodicalExecuter:以給定頻率呼叫一段 JavaScript。例:new PeriodicalExecutor(test, 1),其中 test 是 JavaScript 函數,1 是頻率(1 秒)。
  • $:取得一個元素,等同 getElementById()。例:$('div1')

Field 相關(表單欄位)

  • 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 相關(表單)

  • Form.serialize:把表單內容轉成字串。
  • Form.getElements:以陣列形式取得表單內容。
  • Form.disable:停用表單所有內容。例:Form.disable('form1')(這個好像不太 work)
  • Form.focusFirstElement:把焦點放在表單的第一個元素上。例:Form.focusFirstElement('form1')
  • Form.reset:重設表單。例:Form.reset('form1')
  • Form.Element.getValue:取得表單輸入框的值。例:Form.Element.getValue('text1')
  • Form.Element.serialize:把表單輸入框內容轉成字串。例:Form.Element.serialize('text1')
  • $F:等同 Form.Element.getValue()。例:$F('text1')

Effect 相關(視覺效果)

  • 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 相關

  • Ajax.Request:傳送 Ajax 請求給伺服器。例:Ajax.Request('https://server/s.php')
  • Ajax.Updater:傳送 Ajax 請求給伺服器,並用回傳結果更新指定容器。例: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',...)。

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved