protected void WriteAutoComplete()
{
Response.Write("<Script>" + sZuoZhePinYin + "</Script>");
}
//其中sZuoZhePinYin生成的方式根据要求而定,这里就不是提供详细的代码了。
然后在.aspx的前台使用,整个文件代码如下:
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="QuanZuoZhe.aspx.cs" Inherits="WebApplication1.QuanZuoZhe" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<div style="text-align: center; background: -webkit-gradient(linear, 81% 20%, 10% 21%, from(#ffd800), to(#00CC99))">
<asp:TextBox ID="SearchTextBox" runat="server" CssClass="TextBox"></asp:TextBox>
<asp:Button ID="SearchBtn" runat="server" OnClick="SearchBtn_Click" Text="" CssClass="MySearchBtn"></asp:Button>
</div>
<asp:Label ID="ZuoZheShuoMing_Lbl" runat="server" Text="共有作者4678位。"></asp:Label>
<asp:Label ID="QuanZuoZhe_Lbl" runat="server" Text="此处显示所有作者名字。"></asp:Label>
<asp:Label ID="AllZuoZhe_Lbl" runat="server" Text="所有作者" Visible="False"></asp:Label>
<script type="text/javascript" src="/Scripts/LMQAutoComplete/jquery.js"></script>
<script type="text/javascript" src="/Scripts/LMQAutoComplete/jquery.autocomplete.js"></script>
<link rel="stylesheet" type="text/css" href="/Scripts/LMQAutoComplete/jquery.autocomplete.css" />
<%WriteAutoComplete(); %>
<script>
$(function () {
$("#MainContent_SearchTextBox").autocomplete(availableTags, {
minChars: 1,
matchCase: false,//不区分大小写。插件程序有Bug,全小写可以,大写不可以。如ABC:用abc不可以匹配;而abc:用ABC/abc/AbC等都可以匹配。
autoFill: false,
max: 10,
formatItem: function (row, i, max, term) {
var v = $("#MainContent_SearchTextBox").val();
return row.HanZi + " (" + row.QuanPin + ")";
if (row.HanZi.indexOf(v) >= 0 || row.QuanPin.indexOf(v) >= 0 || row.ShouPin.indexOf(v) >= 0) {
return row.HanZi;//+ " (" + row.QuanPin + ")";
}
else
return false;
},
formatMatch: function (row, i, max) {
return row.HanZi;//+ " (" + row.QuanPin + ")";
},
formatResult: function (row) {
return row.HanZi;
},
reasultSearch: function (row, v)
{
//自定义:在HanZi、QuanPin或ShouPin中匹配
if (row.data.HanZi.indexOf(v) >= 0 || row.data.QuanPin.indexOf(v) >= 0 || row.data.ShouPin.indexOf(v) >= 0) {
return row;
}
else
return false;
}
});
});
</script>
</asp:Content>
代码中引用到的文件,还有整个代码已经打了包,下载地址http://www.xx0594.com/soft/AutoComplete.rar