[原]thinkphp实例下载 ajax自动完成
IndexAction代码:
class IndexAction extends Action
{
function Index()
{
$this->display();
}
function ajaxauto(){//自动完成action
$tagname=$_POST['tagname'];
$dao=D('tpltags');
$r=$dao->findAll("tagname like '%$tagname%'");
$this->assign('list',$r);
$this->display();
}
function showresult(){//显示结果action
$tagname=$_POST['tagname'];
$dao=D('tpltags');
$r=$dao->findAll("tagname like '%$tagname%'");
$this->assign('list',$r);
$this->display();
}
}
首页模板核心:{
function Index()
{
$this->display();
}
function ajaxauto(){//自动完成action
$tagname=$_POST['tagname'];
$dao=D('tpltags');
$r=$dao->findAll("tagname like '%$tagname%'");
$this->assign('list',$r);
$this->display();
}
function showresult(){//显示结果action
$tagname=$_POST['tagname'];
$dao=D('tpltags');
$r=$dao->findAll("tagname like '%$tagname%'");
$this->assign('list',$r);
$this->display();
}
}
<tagLib name='cx,html' />
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<html:link type='css' href='../Public/css/autocomplete.css' />
<html:link type='js' href='../Public/js/prototype.js' />
<html:link type='js' href='../Public/js/effects.js' />
<html:link type='js' href='../Public/js/controls.js' />
<!-- 上面三个js加载顺序为prototype effects controls 不能乱-->
<SCRIPT LANGUAGE="JavaScript">
<!--
//
window.onload = function ()
{
new Ajax.Autocompleter("tagname","autocomplete", "__URL__/ajaxauto", {});
}
function showResults(){
new Ajax.Updater('description', '__URL__/showresult', {method:'post', postBody:'tagname='+$F('tagname')});
new Effect.Appear('description');
}
//-->
</SCRIPT>
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<html:link type='css' href='../Public/css/autocomplete.css' />
<html:link type='js' href='../Public/js/prototype.js' />
<html:link type='js' href='../Public/js/effects.js' />
<html:link type='js' href='../Public/js/controls.js' />
<!-- 上面三个js加载顺序为prototype effects controls 不能乱-->
<SCRIPT LANGUAGE="JavaScript">
<!--
//
window.onload = function ()
{
new Ajax.Autocompleter("tagname","autocomplete", "__URL__/ajaxauto", {});
}
function showResults(){
new Ajax.Updater('description', '__URL__/showresult', {method:'post', postBody:'tagname='+$F('tagname')});
new Effect.Appear('description');
}
//-->
</SCRIPT>
下载地址:
/Files/webeasy/autosearch.rar (仅app 不含框架 框架请到thinkphp.cn下载)