您的位置:首页 > 编程语言 > Go语言

用AJAX实现google输入自动完成的简单模拟

2007-07-10 16:17 579 查看
比较简单的模拟,文本框输入CompanyName,然后
搜索SqlServer2000 里NorthWind数据库 Suppliers表的CompanyName字段,
然后实现自动完成

四个文件
1 .AutoComplete.htm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2<html xmlns="http://www.w3.org/1999/xhtml" >
3<head>
4 <title>输入自动完成</title>
5</head>
189<body onload="initPar()">
190CompanyName<input type="text" id="txtCompanyName" onkeyup="autoComplete()" onblur="setDisplay();" style="width:400px"/>
191<!-- 显示下拉表的div-->
192<div id="divContent" style="display:none; position:absolute; ">
193</div>
194</body>
195</html>
196

AutoComplete.aspx

AutoComplete.aspx.cs

using System;
2using System.Data;
3using System.Data.SqlClient;
4using System.Configuration;
5using System.Collections;
6using System.IO;
7using System.Text;
8using System.Web;
9using System.Web.Security;
10using System.Web.UI;
11using System.Web.UI.WebControls;
12using System.Web.UI.WebControls.WebParts;
13using System.Web.UI.HtmlControls;
14using System.Web.Configuration;
15
16namespace AJAXBaseHome
17

xslt文件 用于显示xml数据

<?xml version="1.0" encoding="UTF-8" ?>
2<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
3 <xsl:output method="html"/>
4 <xsl:template match="/">
5 <xsl:apply-templates/>
6 </xsl:template>
7 <xsl:template match="NewDataSet">
8 <table id="tblContent" style="background-color:GrayText">
9 <xsl:for-each select="Table">
10 <tr>
11 <!--td中单击时选择当前值, 鼠标在上时更改行背景颜色,鼠标离开后清除背景颜色-->
12 <td onclick="selValue()" style="cursor:hand" onmouseover="clearColor();this.parentElement.style.backgroundColor='InfoBackground'" onmouseout="clearColor()">
13 <xsl:value-of select="CompanyName"/>
14 </td>
15 </tr>
16 </xsl:for-each>
17 </table>
18 </xsl:template>
19</xsl:stylesheet>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: