- 資訊首頁(yè) > 開(kāi)發(fā)技術(shù) >
- 怎么用ajax+php實(shí)現搜索框自動(dòng)填充功能
這篇文章主要講解了“怎么用ajax+php實(shí)現搜索框自動(dòng)填充功能”,文中的講解內容簡(jiǎn)單清晰,易于學(xué)習與理解,下面請大家跟著(zhù)小編的思路慢慢深入,一起來(lái)研究和學(xué)習“怎么用ajax+php實(shí)現搜索框自動(dòng)填充功能”吧!
復制代碼 代碼如下:
<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 >
<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è)面一
復制代碼 代碼如下:
<?
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();
?>
免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng )、來(lái)自互聯(lián)網(wǎng)轉載和分享為主,文章觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權請聯(lián)系QQ:712375056 進(jìn)行舉報,并提供相關(guān)證據,一經(jīng)查實(shí),將立刻刪除涉嫌侵權內容。
Copyright ? 2009-2021 56dr.com. All Rights Reserved. 特網(wǎng)科技 特網(wǎng)云 版權所有 珠海市特網(wǎng)科技有限公司 粵ICP備16109289號
域名注冊服務(wù)機構:阿里云計算有限公司(萬(wàn)網(wǎng)) 域名服務(wù)機構:煙臺帝思普網(wǎng)絡(luò )科技有限公司(DNSPod) CDN服務(wù):阿里云計算有限公司 中國互聯(lián)網(wǎng)舉報中心 增值電信業(yè)務(wù)經(jīng)營(yíng)許可證B2
建議您使用Chrome、Firefox、Edge、IE10及以上版本和360等主流瀏覽器瀏覽本網(wǎng)站