国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

Ajax文本框輸入提示

2019-11-17 04:18:32
字體:
供稿:網(wǎng)友

今天我來做一個Ajax文本框輸入提示的例子:

前臺文件

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<html xmlns="<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>文本框輸入提示</title>
<style type="text/
CSS">...
<!--
.keyWord {...}{width:150px; height:20px; border:#0066FF 1px solid;}/**//*文本框樣式*/
#keytishi {...}{width:150px; height:auto; border:#0066FF 1px solid; position:absolute; display:none;}/**//*提示層樣式*/
#keytishi ul {...}{ margin:0;}/**//*提示層樣式*/
#keytishi ul li{...}{margin:0;list-style-type:none; line-height:16px; height:16px; font-size:12px; padding:2px;}/**//*提示層樣式*/
#keytishi ul li a {...}{display:block; width:150px; height:16px; text-decoration:none;}/**//*提示層樣式*/
#keytishi ul li a:hover {...}{background-color:#0099FF;}/**//*提示層樣式*/
-->
</style>
<script type="text/javascript">...
<!--

//建立xmlhttpRequest對象
var xmlhttp;
try...{
    xmlhttp= new ActiveXObject('Msxml2.XMLHTTP');
}catch(e)...{
    try...{
        xmlhttp= new ActiveXObject('Microsoft.XMLHTTP');
    }catch(e)...{
        try...{
            xmlhttp= new XMLHttPRequest();
        }catch(e)...{}
    }
}

function getKeyWord()...{
    var obj = document.getElementById("search");//獲取文本域?qū)ο?BR>    if(obj.value=="")...{
        return;
    }
    var top=0;
    var left=0;
    while(obj)...{//此循環(huán)得到文件域?qū)ο笤陧撁嬷械慕^對位置
        top += obj["offsetTop"];
        left += obj["offsetLeft"];
        obj = obj.offsetParent;
    }
    xmlhttp.open("get","input.asp?keyword="+document.getElementById("search").value,true);
    xmlhttp.onreadystatechange = function()...{
        if(xmlhttp.readyState == 4)
        ...{
            if(xmlhttp.status == 200)
            ...{
                if(xmlhttp.responseText!="")...{
                    document.getElementById("keytishi").innerHTML = unescape(xmlhttp.responseText);//把后臺返回的數(shù)據(jù)填充到提示層
                    document.getElementById("keytishi").style.left = left + "px";//設(shè)置提示層的位置,左
                    document.getElementById("keytishi").style.top = (top + 25) + "px";//設(shè)置提示層的位置,上
                    document.getElementById("keytishi").style.display = "block";//設(shè)置提示層可見
                }else...{
                    document.getElementById("keytishi").innerHTML = "";//清空提示層
                    document.getElementById("keytishi").style.display = "none";//設(shè)置提示層不可見
                }
            }
            else...{
           
            }
        }
    }
    xmlhttp.setRequestHeader("If-Modified-Since","0");
    xmlhttp.send(null);
}
function input(str)...{
    document.getElementById("search").value=str;//從提示層選擇你需要的數(shù)據(jù)填充到文本框
    document.getElementById("keytishi").innerHTML = "";//清空提示層
    document.getElementById("keytishi").style.display = "none";//設(shè)置提示層不可見
}
//-->
</script>
</head>
<body>
<input type="text" class="keyword" id="search" name="search" onkeyup="getKeyWord();" onclick="getKeyWord();" />
<div id="keytishi"></div><!--提示層-->
</body>
</html>

后臺文件 [input.asp]

 

<%...@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#include file="conn.asp"-->
<%...
    dim rs
    dim sql
   
    dim keyWords
   
    keyWrods = Request("keyword")
   
    Set rs = Server.CreateObject("ADODB.Recordset")
    sql = "select * from king_test where keyword like '%"&keyWrods&"%'"
    rs.open sql,conn,1,1
    if not (rs.bof and rs.eof) then
    Response.Write("<ul>")
    do while not rs.eof
%>
<li><a href="Javascript:void(null);" onclick="input('<%Response.Write(escape(rs("keyword")))%>');"><%...Response.Write(escape(rs("keyword")))%></a></li>
<%...
    rs.movenext
    loop
    Response.Write("<ul>")
    end if
    rs.close
    set rs = nothing
    conn.close
    Set conn = nothing
%>
 

escape與unescape是用來編碼的和解碼的,這是為了避免漢字出現(xiàn)亂碼

在XP + IE6,7,Firefox測試通過


發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 吉木乃县| 朔州市| 托克托县| 普陀区| 广州市| 石嘴山市| 额济纳旗| 平罗县| 民乐县| 青冈县| 临武县| 江源县| 北京市| 留坝县| 纳雍县| 嘉义县| 乳源| 桐乡市| 德格县| 深州市| 嵩明县| 鄂托克前旗| 黎城县| 阳春市| 临泽县| 长寿区| 阿瓦提县| 密山市| 沙田区| 剑阁县| 福州市| 台中市| 马龙县| 崇仁县| 齐齐哈尔市| 梓潼县| 景宁| 通江县| 宣武区| 宜州市| 玉溪市|