主頁 > 知識庫 > ASP模仿google suggest風(fēng)格實(shí)現(xiàn)下拉菜單效果

ASP模仿google suggest風(fēng)格實(shí)現(xiàn)下拉菜單效果

熱門標(biāo)簽:不封卡外呼系統(tǒng)一般多少錢 微信地圖標(biāo)注有什么用 濰坊呼叫中心外呼系統(tǒng)供應(yīng)商 北京大興區(qū)地圖標(biāo)注 地圖標(biāo)注中心多少錢注冊 鄭州語音電銷機(jī)器人官網(wǎng) 電銷機(jī)器人一個多少錢 重慶外呼電銷系統(tǒng)費(fèi)用 地圖標(biāo)注不完整被罰款

今天和大家一起利用ASP模仿實(shí)現(xiàn)google suggest風(fēng)格的下拉菜單,直接上代碼

1.前臺代碼:

%@LANGUAGE="JAVASCRIPT" CODEPAGE="936"%>
!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">
style type="text/css">
!--
.style1 {color: #FF0000}
.mouseOut
{
font-size:12px;
background: #708090;
color: #FFFAFA;
}
  
.mouseOver
{
font-size:12px;
background: #FFFAFA;
color: #000000;
}
-->
/style>
   script type="text/javascript" language="javascript">
    var xmlHttp;
    var completeDiv;
    var inputField;
    var nameTable;
    var nameTableBody;
    var flag=false;
  
    function createXMLHttpRequest() {
      if (window.ActiveXObject) {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
      }
      else if (window.XMLHttpRequest) {
        xmlHttp = new XMLHttpRequest();        
      }
    }
    
    function setflag(){
      flag = true;
    }
    
    function DisSelect()
    {
      if(flag==false)
      document.getElementById("popup").style.display="none";
    }
  
    function initVars() {
      inputField = document.getElementById("frmchangshang");      
      nameTable = document.getElementById("name_table");
      completeDiv = document.getElementById("popup");
      nameTableBody = document.getElementById("name_table_body");
      document.getElementById("popup").style.display="block";
    }
  
    function findNames() {
      initVars();
      if (inputField.value.length > 0)
  {
        createXMLHttpRequest();
        var url = "search.asp?names=" + inputField.value; 
        xmlHttp.open("GET", url, true);
        xmlHttp.onreadystatechange = callback;
        xmlHttp.send(null);
      }
  else
  {
        clearNames();
      }
    }
  
    function callback() {
      if (xmlHttp.readyState == 4) {
        if (xmlHttp.status == 200)
        {
   try
          {
            var name = xmlHttp.responseXML.getElementsByTagName("name")

[0].firstChild.data;
          }
          catch(e)
          {
            document.getElementById("popup").style.display="none";
            clearNames();
          }
          setNames(xmlHttp.responseXML.getElementsByTagName("content"));
        }
        else if (xmlHttp.status == 204)
        {
          clearNames();
        }
      }
    }
    
    function setNames(the_names) {      
      clearNames();
      var size = the_names.length;
      setOffsets();
      var row,cell,spans;
      for (var i = 0; i  size; i++) {
        //var nextNode = the_names[i].firstChild.data;
  var e = the_names[i];
  //取得子節(jié)點(diǎn)內(nèi)容,重新裝載為數(shù)組
  var nextNode=e.getElementsByTagName("name")[0].firstChild.data;
  //創(chuàng)建tr,td,span元素
        row =document.createElement("tr");
        cell =document.createElement("td");
  //spans=document.createElement("span");
  //設(shè)置cell屬性
        cell.onmouseout = function() {this.className='mouseOver'; flag=false;};
        cell.onmouseover = function() {this.className='mouseOut'; flag=true;};
        cell.setAttribute("bgcolor","#FFFAFA");
        cell.setAttribute("border","0");
        //cell.setAttribute("onmouseover","setflag()");
        cell.onclick = function() { populateName(this); };
  //將nextNode添加到td
  var txtName = document.createTextNode(nextNode);
  cell.appendChild(txtName);
  //裝載隱藏?cái)?shù)據(jù)到span元素
  row.appendChild(cell);
        nameTableBody.appendChild(row);
      }
    }
  
    function setOffsets() {
      var end = inputField.offsetWidth;
      var left = calculateOffsetLeft(inputField);
      var top = calculateOffsetTop(inputField) + inputField.offsetHeight;
  
      completeDiv.style.border = "black 1px solid";
      completeDiv.style.left = left + "px";
      completeDiv.style.top = top + "px";
      nameTable.style.width="400px";
    }
    
    function calculateOffsetLeft(field) {
     return calculateOffset(field, "offsetLeft");
    }
  
    function calculateOffsetTop(field) {
     return calculateOffset(field, "offsetTop");
    }
  
    function calculateOffset(field, attr) {
     var offset = 0;
     while(field) {
      offset += field[attr];
      field = field.offsetParent;
     }
     return offset;
    }
  
    function populateName(cell) {
  //填充數(shù)據(jù)到web頁面,cell---->td對象
      inputField.value = cell.firstChild.nodeValue;
      clearNames();
    }
    //清除列表數(shù)組
    function clearNames() {
      var ind = nameTableBody.childNodes.length;
      for (var i = ind - 1; i >= 0 ; i--) {
         nameTableBody.removeChild(nameTableBody.childNodes[i]);
      }
      completeDiv.style.border = "none";
    }
/script>
head>
meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
title>Untitled Document/title>
/head>
  
body>
input name="frmchangshang" class="InputText" id="frmchangshang" style="width:250px;" 

onBlur="DisSelect();" onKeyUp="findNames();" size="50" maxlength="100">
          nbsp;span class="style1">提示:輸入關(guān)鍵字,程序自動從庫中匹配您

要找的記錄,如果不存在自行填寫
     /span>
          div style="position:absolute;top:0;left:0;" id="popup">
            table id="name_table" bgcolor="#FFFAFA" border="0" cellspacing="0" 

cellpadding="0">      
              tbody id="name_table_body">/tbody>
            /table>
         /div>
/body>
/html>

2.后臺search.asp異步查詢數(shù)據(jù)頁面
把sql語句和要顯示的字段改為自己的數(shù)據(jù)庫相對應(yīng)格式就可以了。

!--#include virtual="conn.asp" -->
%
keyword=request.QueryString("names")
sql="select lgid,lgmc from lg where lgmc like '%"keyword"%' order by lgid desc"
set rs=server.CreateObject("adodb.recordset")
rs.open sql,conn,1,1
Response.ContentType="text/xml"  
response.Write "?xml version=""1.0"" encoding=""GB2312"" ?>"
response.Write "response>"
do while not rs.eof
response.Write "content>"
response.Write "name>"rs("lgmc")"/name>"
'response.Write "userid>"rs("userid")"/userid>"
'response.Write "startime>"rs("startime")"/startime>"
'response.Write "endtime>"rs("endtime")"/endtime>"
response.Write "/content>"
rs.movenext
loop
response.Write "/response>"
rs.close
set rs=nothing
%>

以上就是ASP模仿google suggest風(fēng)格實(shí)現(xiàn)下拉菜單效果的代碼,希望對大家的學(xué)習(xí)有所幫助。

您可能感興趣的文章:
  • Google Suggest ;-) 基于js的動態(tài)下拉菜單
  • ASP+JS三級聯(lián)動下拉菜單[調(diào)用數(shù)據(jù)庫數(shù)據(jù)]
  • AJAX實(shí)現(xiàn)仿Google Suggest效果
  • 仿google搜索提示 SuggestFramework的使用
  • ASP.NET 2.0寫無限級下拉菜單
  • ajax Suggest類似google的搜索提示效果
  • google suggest 下拉菜單實(shí)現(xiàn)代碼(asp.net版本)
  • asp.net DropDownList 三級聯(lián)動下拉菜單實(shí)現(xiàn)代碼

標(biāo)簽:攀枝花 撫州 汕頭 鶴崗 揭陽 唐山 佛山 海南

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《ASP模仿google suggest風(fēng)格實(shí)現(xiàn)下拉菜單效果》,本文關(guān)鍵詞  ASP,模仿,google,suggest,風(fēng)格,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《ASP模仿google suggest風(fēng)格實(shí)現(xiàn)下拉菜單效果》相關(guān)的同類信息!
  • 本頁收集關(guān)于ASP模仿google suggest風(fēng)格實(shí)現(xiàn)下拉菜單效果的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章