日期:2014-05-17 浏览次数:20443 次
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="index.aspx.cs" Inherits="index" %> <!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 runat="server"> <title>文本框输入自动提示</title> <script type="text/javascript" src="js/jquery-1.4.2.min.js"></script> <script type="text/javascript" src="js/jquery.autocomplete.min.js"></script> <link rel="Stylesheet" href="js/jquery.autocomplete.css" /> <script type="text/javascript"> var emails=<%=tip%>; $(function() { $('#keyword').autocomplete(emails, { max:10, //列表里的条目数 minChars: 0, //自动完成激活之前填入的最小字符 width: 400, //提示的宽度,溢出隐藏 scrollHeight: 300, //提示的高度,溢出显示滚动条 matchContains: true, //包含匹配,就是data参数里的数据,是否只要包含文本框里的数据就显示 autoFill: false, //自动填充 //提示 formatItem: function(row, i, max) { return i + '/' + max + ':"' + row.name + '"[' + row.to + ']'; }, //匹配 formatMatch: function(row, i, max) { return row.name + row.to; }, //结果 formatResult: function(row) { return row.name; } }).result(function(event, row, formatted) { document.getElementById("keyword2").value=row.to; }); }); </script> </head> <body> <form id="form1" runat="server"> <div> Name: <asp:TextBox ID="keyword" runat="server"></asp:TextBox><br /> Email: <asp:TextBox ID="keyword2" runat="server"></asp:TextBox> </div> </form> </body> </html>
using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System.Collections.Generic; using System.Data.SqlClient; public partial class index : System.Web.UI.Page { public string tip = ""; protected void Page_Load(object sender, EventArgs e) { IList<ACSClass> list = GetACSClassList(); string str = "["; for (int i = 0; i < list.Count; i++) { ACSClass acsclass = (ACSClass)list[i]; str += "{name:'" + acsclass.Classcode + "',to:'" + acsclass.Classname + "'},"; } str = str.Substring(0, str.Length - 1);//去掉最后一个逗号 str += "]"; tip = str.ToString(); }