xajax 0.5版本方法集


现在最新的XAJAX版本已经0.5 Beta4了。可是网上能找到的资料都只是0.25版的。没办法只好自己看源代码了。xajax的核心其实是xajaxResponse类,这里整理了一下它的常用方法:

  xajaxResponse类的常用方法合集

  1. xajaxResponse->confirmCommands($iCmdNumber,$sMessage)

  弹出询问对话框,询问内容为$sMessage,第一个参数$iCmdNumber为数字。如果用户选择了“是”,则此语句后的一句或多句语句都会执行;如果用户选择了“否”,那么,则跳过前$iCmdNumber句再执行,即只有自第$iCmdNumber句起之后的语句(不包括第$ iCmdNumber句)会执行。

  例:$xResponse->confirmCommands(4,'请确认是否真的删除记录');

  2. xajaxResponse->assign($sTarget,$sAttribute,$sData)

  给元素ID为$sTarget的属性赋值,把它的属性$sAttribute值赋为$sData.

  例:$xResponse->assign('mydiv','innerHTML','Hello world! This is a example of xajax!');

  $xResponse->assign('mydiv','style.color','blue');

  $xResponse->assign('forminput','value','Bill');

  3. xajaxResponse->append($sTarget,$sAttribute,$sData)

  给ID为$sTarget的元素属性以追加方式赋值。在它的属性$sAttribute的原有值的基础上追加赋值$sData。

  例:$xResponse->append('mydiv','innerHTML','This is append comment');

  4. xajaxResponse->prepend($sTarget,$sAttribute,$sData)

  同上,是预赋值。具体什么是预赋值,还没弄明白
5. xajaxResponse->replace($sTarget,$sAttribute,$sSearch,$sData)

  替换ID为$sTarget的元素的属性值。把属性$sAttribute的值中所有包含$sSearch的值替换为$sData。

  例:$xResponse->replace('mydiv','innerHTML','xajax','<strong>xajax</strong>');

  [突然明白了GOOGLE,BAIDU等搜索引擎的搜索页面中的关键字高亮是怎么实现的了。]

  6. xajaxResponse->clear($sTarget,$sAttribute)

  清除ID为$sTarget的元素属性值。清除它的$sAttribute的属性的值。

  例:$xResponse->clear('mydiv','innerHTML');

  7. xajaxResponse->alert($sMsg)

  弹出对话框,内容为$sMsg。即JS中的window.alert()方法。

  例:$xResponse->alert('How are you?');

  8. xajaxResponse->redirect($sURL,$iDelay=0)

  重定向。让浏览器$iDelay秒后转向$sURL。$iDelay省略时默认为0。即JS中的window.location()方法。

  例:$xResponse->redirect('http://www.sohu.com' ,15);

  9. xajaxResponse->script($sJS)

  执行一段JS脚本。参数$sJS为JS代码。

  例:$xResponse->script("alert("hello world")");

  10. xajaxResponse->create($sParent,$sTag,$sId,$sType=null)

  在当前已存在的元素$sParent下创建一个$sTag元素,并把它的ID设为$sId。

  例:$xResponse->create('mydiv','span','myspan');

  11. xajaxResponse->remove($sTarget)

  移除一个ID为$sTarget的元素
例:$xResponse->remove('mydiv');

  12. xajaxResponse->insert($sBefore,$sTag,$sId)

  在当前元素$sBefore之前插入一个元素$sTag,并把$sTag元素的ID设置为$sId。

  例:$xResponse->insert('myspan','p','myp');

  13. xajaxResponse->insertAfter($sAfter,$sTag,$sId)

  同上,只不过不是在之前插入元素,是是在元素$sAfter之后插入。

  14. xajaxResponse->createInput($sParent,$sType,$sName,$sId)

  以$sParent为父元素,创建一个INPUT元素,并把它的类型设置为$sType[即:type="$sType"],把元素的NAME设置为$sName[即:name="$sName"],把元素ID设置为$sId[即:id="$sId"]。

  例:$xResponse->createInput('mydiv','text','username','input1');

  15. xajaxResponse->insertInput($sBefore,$sType,$sName,$sId)

  在元素$sBefore之前插入一个INPUT元素,并设置:type="$sType" name="$sName" id="$sId"。

  例:$xResponse->insertInput('input1','password','userpass','input2');

  16. xajaxResponse->insertInputAfter($sAfter,$sType,$sName,$sId)

  在元素$sAfter之后插入一个INPUT元素,并设置:type="$sType" name="$sName" id="$sId"。

  例:$xResponse->insertInputAfter('input2','text','checkcode','input3');

  以上只是一些常用的方法,还有很多高级的方法,一时未能明了。希望高手补充啊


« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3