ajax+php 谷歌搜索框自動(dòng)填充功能 實(shí)例代碼
更新時(shí)間:2009年11月26日 00:31:26 作者:
應(yīng)用Ajax技術(shù) 結(jié)合php語(yǔ)言寫的簡(jiǎn)單的類谷歌搜索框自動(dòng)填充功能。
復(fù)制代碼 代碼如下:
<html>
<head>
<script language="javascript"><!--
var http_request;
function update(v){
if (window.XMLHttpRequest) { // Mozilla, Safari, ...
http_request = new XMLHttpRequest();
} else if (window.ActiveXObject) { // IE
http_request = new ActiveXObject("Microsoft.XMLHTTP");
}
http_request.onreadystatechange=out;
var url="tp.phtml?worksheet="+v.value;
http_request.open('GET',url,true);
http_request.send(null);
}
function out(){
if(http_request.readyState == 4){
var div=document.getElementById('out');
if(http_request.responseText!='') {
div.style.display='block';
div.innerHTML=http_request.responseText;
//alert(div.innerHTML);
}else{
div.style.display='none';
div.innerHTML='';
}
}
}
function end(val){
document.getElementById('ws').value=val;
document.getElementById('out').innerHTML='';
document.getElementById('out').style.display='none';
}
// --></script>
<style><!--
.test{
display:none;
z-index:100;
width:150px;
top:20px;
left:0px;
height:auto;
background-color:lightgrey;
border:1px solid;
position:absolute;
}
a:link {
text-decoration:none;
color:black;
}
a:visited {
text-decoration:none;
color:black;
}
a:hover {
text-decoration:none;
color:black;
}
--></style>
</head>
<body>
<div style="position:relative;" style="position:relative;">
<input type='txt' id='ws' name='ws' value='' onPropertyChange='update(this);' oninput='update(this);'/> <div id='out' class='test'></div>
<div>
<input type='txt' id='d'/>
</body>
</html>
頁(yè)面一
復(fù)制代碼 代碼如下:
<?
include("include/db.inc");
$ws=$_GET['worksheet'];
if(empty($ws)||strlen($ws)<3){
//echo 'oo';
exit();
}
$db=new db();
$str='';
$sql="select * from user where deptID=10 and status='On' and worksheet like '%$ws%' order by worksheet";
$rt=$db->rtAssoc($sql);
while($row=array_shift($rt)){
$str.="<a href="\" href="\""#\" onclick=\"end('"
.$row['emp_name'].':'.$row['emp_worksheet']."');\">"
.$row['emp_name'].':'.$row['emp_worksheet']
.'</a>,<br/>';
}
$str=substr($str,0,-6);
echo trim($str);
exit();
?>
頁(yè)面二。
這個(gè)東西功能上模仿谷歌,但是效果很不理想。一般簡(jiǎn)單的應(yīng)用可以滿足
您可能感興趣的文章:
- ThinkPHP實(shí)現(xiàn)ajax仿官網(wǎng)搜索功能實(shí)例
- Thinkphp搜索時(shí)首頁(yè)分頁(yè)和搜索頁(yè)保持條件分頁(yè)的方法
- ThinkPHP讓分頁(yè)保持搜索狀態(tài)的方法
- ThinkPHP使用getlist方法實(shí)現(xiàn)數(shù)據(jù)搜索功能示例
- ThinkPHP設(shè)置禁止百度等搜索引擎轉(zhuǎn)碼(簡(jiǎn)單實(shí)用)
- php+ajax實(shí)時(shí)輸入自動(dòng)搜索匹配的方法
- php+ajax做仿百度搜索下拉自動(dòng)提示框(有實(shí)例)
- php+ajax實(shí)現(xiàn)仿百度查詢下拉內(nèi)容功能示例
- thinkPHP+mysql+ajax實(shí)現(xiàn)的仿百度一下即時(shí)搜索效果詳解
相關(guān)文章
ajax動(dòng)態(tài)為a標(biāo)簽href賦值不執(zhí)行跳轉(zhuǎn)的原因分析及解決
ajax 動(dòng)態(tài)為a標(biāo)簽的href屬性賦值,總是不執(zhí)行跳轉(zhuǎn)的原因想必大家有遇到過(guò)吧,下面與大家分享下具體的解決方法,希望對(duì)你有所幫助2013-06-06
ajax動(dòng)態(tài)查詢數(shù)據(jù)庫(kù)數(shù)據(jù)并顯示在前臺(tái)的方法
今天小編就為大家分享一篇ajax動(dòng)態(tài)查詢數(shù)據(jù)庫(kù)數(shù)據(jù)并顯示在前臺(tái)的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-08-08
Ajax技術(shù)(WEB無(wú)刷新提交數(shù)據(jù))
Ajax技術(shù)(WEB無(wú)刷新提交數(shù)據(jù))...2007-02-02
ajax回調(diào)打開(kāi)新窗體防止瀏覽器攔截有效方法
這篇文章主要為大家詳細(xì)介紹了ajax回調(diào)打開(kāi)新窗體防止瀏覽器攔截的有效方法,感興趣的朋友可以參考一下2016-05-05
ajax回調(diào)函數(shù)中使用$(this)取不到對(duì)象的解決方法
如果在ajax的回調(diào)函數(shù)內(nèi)使用$(this)的話,實(shí)踐證明,是取不到任何對(duì)象的,需要的朋友可以參考下2014-06-06

