xajax 0.2.4新增的几个有用方法


今天在phpe看到xajax新版本0.2.4出来了,增加了几个有用的方法:

  addScriptCall方法:调用客户端的javascript函数,支持从服务器端传递参数给客户端的javascript函数。

  在以前的版本,如果要在客户端执行反馈的js效果,必须用addScript方法传递大量的js代码到客户端,感觉比较笨重。现在的才是合理的模式:ajax只传递数据。

  addInsertInputAfter方法: 向页面某个元素后动态添加text, radio, checkbox等表单。是以前的addInsertInput功能扩展,addInsertInput是向某个元素之前添加。

  addConfirmCommands方法:我感觉是在模拟js的confirm函数,不过它的跳转不是用返回false或true来控制,而是如果用户点confirm对话框中的"取消",就跳过addConfirmCommands第一个参数传递的服务器端命令的条数。

  例子:

<?php
require("../xajax.inc.php");
  
function callScript()
{
$response = new xajaxResponse();
$value2 = "this is a string";
$response->addConfirmCommands(1, "Do you want to preview the new data?");
$response->addClear("t1","innerHTML");
$response->addClear("t2","innerHTML");
return $response;
}
  
$xajax = new xajax();
//$xajax->debugOn();
$xajax->registerFunction("callScript");
$xajax->processRequests();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>addConfirmCommands Test | xajax Tests</title>
<?php $xajax->printJavascript("../") ?>
  
</head>
<body>
  
<h1>addConfirmCommands Test</h1>
  
<p>eb163.com. <input type="button" value="Click Me" onclick="xajax_callScript()" /></p>
  
<div id="t1">www</div>
<div id="t2">eee</div>
  
</body>
</html>


« 
» 
快速导航

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