Ajax文本框输入提示

解小夕

解小夕

2016-02-19 19:19

下面,图老师小编带您去了解一下Ajax文本框输入提示,生活就是不断的发现新事物,get新技能~

一个Ajax文本框输入提示的例子,用asp实现:

前台文件

(本文来源于图老师网站,更多请访问https://m.tulaoshi.com/webkaifa/)

!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" / 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");//获取文本域对象      if(obj.value=="")...{          return;      }      var top=0;      var left=0;      while(obj)...{//此循环得到文件域对象在页面中的绝对位置          top += obj["offsetTop"];          left += obj["offsetLeft"];          objobj = 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);//把后台返回的数据填充到提示层                      document.getElementById("keytishi").style.left = left + "px";//设置提示层的位置,左                      document.getElementById("keytishi").style.top = (top + 25) + "px";//设置提示层的位置,上                      document.getElementById("keytishi").style.display = "block";//设置提示层可见                  }else...{                      document.getElementById("keytishi").innerHTML = "";//清空提示层                      document.getElementById("keytishi").style.display = "none";//设置提示层不可见                  }              }              else...{                            }          }      }      xmlhttp.setRequestHeader("If-Modified-Since","0");      xmlhttp.send(null);  }  function input(str)...{      document.getElementById("search").value=str;//从提示层选择你需要的数据填充到文本框      document.getElementById("keytishi").innerHTML = "";//清空提示层      document.getElementById("keytishi").style.display = "none";//设置提示层不可见  }  //-- /script /head body input type="text" class="keyword" id="search" name="search" onkeyup="getKeyWord();" onclick="getKeyWord();" / div id="keytishi"/div!--提示层-- /body /html 后台文件 [input.asp]

(本文来源于图老师网站,更多请访问https://m.tulaoshi.com/webkaifa/)

%...@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  % lia 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是用来编码的和解码的,这是为了避免汉字出现乱码,在XP + IE6,7,Firefox测试通过

展开更多 50%)
分享

猜你喜欢

Ajax文本框输入提示

Web开发
Ajax文本框输入提示

正则文本框只能输入正整数

Web开发
正则文本框只能输入正整数

s8lol主宰符文怎么配

英雄联盟 网络游戏
s8lol主宰符文怎么配

文本框输入多重幂指数的方法

电脑入门
文本框输入多重幂指数的方法

使用C# 开发掩码输入文本框

电脑网络
使用C# 开发掩码输入文本框

lol偷钱流符文搭配推荐

英雄联盟 网络游戏
lol偷钱流符文搭配推荐

ajax 服务器文本框自动填值

Web开发
ajax 服务器文本框自动填值

VB经验谈:限制输入的文本框

编程语言 网络编程
VB经验谈:限制输入的文本框

lolAD刺客新符文搭配推荐

英雄联盟
lolAD刺客新符文搭配推荐

Ajax不只是炫技[Ajax进阶开发]

Ajax不只是炫技[Ajax进阶开发]

AJAX开发技术在PHP开发过程中的简单应用技巧

AJAX开发技术在PHP开发过程中的简单应用技巧
下拉加载更多内容 ↓