问题是:jquery官方没有提供如何实现输入“w” 就在下拉列宽中显示“王”,可官方的autocomplete没有这功能,请问如何修改,谢谢。 主要是对auto-complete这插件的修改,这我有点不懂,有哪位高手可以教下,谢谢。
<!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     <script src="../script/jquery-1.4.3.js" type="text/javascript"></script>
 6     <link href="../css/jquery.autocomplete.css" rel="stylesheet" type="text/css" />
 7     <script src="../script/jquery.autocomplete.js" type="text/javascript"></script>
 8 
 9     <style type="text/css">
10     
11     </style>
12     <script type="text/javascript">
13         $(function () {
14             $("input").focus(function () {
15 
16                 /*$.ajax({
17                 type: "GET",
18                 dataType: "text",
19                 url: "complete.aspx",
20                 success: function (data, textStatus) {
21                 var str = data.split(",");
22 
23 
24                 $("#autocomplete").autocomplete(str);
25                 }
26                 })  */
27 
28                 $("#autocomplete").autocomplete(complete.aspx, {
29                     max: 50,    //列表里的条目数
30                     minChars: 0,    //自动完成激活之前填入的最小字符
31                     width: 400,     //提示的宽度,溢出隐藏
32                     scrollHeight: 1000,   //提示的高度,溢出显示滚动条
33                     matchContains: true,    //包含匹配,就是data参数里的数据,是否只要包文本框里的数据就显示
34                     autoFill: false,    //自动填充
35                     formatItem: function (row, i, max) {
36 
37                         var obj = eval("(" + row + ")"); //转换成js对象
38                         return obj.Text;
39                     },
40                     formatMatch: function (row, i, max) {
41                         var obj = eval("(" + row + ")"); //转换成js对象
42                         return obj.Text;
43                     },
44                     formatResult: function (row) {
45                         var obj = eval("(" + row + ")"); //转换成js对象
46                         return obj.Text;
47                 }).result(function (event, row, formatted) {
48 
49                 });
50             });
51 
52 
53             $("#loading").ajaxStart(function () {
54                 $(this).show();
55             });
56             $("#loading").ajaxStop(function () {
57                 $(this).hide();
58             });
59 
60         })
61          
62     </script>
63 </head>
64 <body>
65 
66  
67  <p>mystring</p>
68 <div id="mystring"></div>
69 <input type="text" id="autocomplete" />
70 <div id="loading" style="display:none">请稍等:</div>
71 </body>
72 </html>后台代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;namespace Maticsoft.Web.autocomplete
{
    public partial class conplete : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
           string strResult = "{text:'Link A', url:'/page1'}\n {text:'Link B', url: '/page2'} ";
            Response.Write(strResult);
        }
    }
}关键问题是如何像aspx读取数据,其数据格式是什么的?谢谢

解决方案 »

  1.   

    我真是用ajax读取数据的,就是不知道怎么实现输入“w” 就在下拉列宽中显示“王”
      

  2.   

    恩,思路是挺不错的,可是我这录入时根据需要在后台录入的,然后再前台展示的, ,要不我发一段代码你看看,他是可以实现以上功能,但我不知道他的原理.网址是:http://www.cnblogs.com/eflylab/archive/2009/09/18/1569043.html
    以上网址的内容你看看,我不理解其原理
      

  3.   

    我是做C#的,这有一个获取获取 汉字 拼音首字母的方法:你参考一下 public static  class DisposeChina
        {
            //获取简体中文字符串拼音首字母 
            public static string GetSpells(string input)
            {
                int len = input.Length;
               StringBuilder  sbVal =new StringBuilder();
                for (int i = 0; i < len; i++)
                {
                    sbVal.Append(GetSpell(input.Substring(i, 1)));
                }
                return sbVal.ToString();
            }        //获取一个简体中文字的拼音首字母 
            public static string GetSpell(string cn)
            {
                byte[] arrCN = System.Text.Encoding.Default.GetBytes(cn);
                if (arrCN.Length > 1)
                {
                    int area = (short)arrCN[0];
                    int pos = (short)arrCN[1];
                    int code = (area << 8) + pos;
                    int[] areacode = { 45217, 45253, 45761, 46318, 46826, 47010, 47297, 47614, 48119, 48119, 49062, 49324, 49896, 50371, 50614, 50622, 50906, 51387, 51446, 52218, 52698, 52698, 52698, 52980, 53689, 54481 };
                    for (int i = 0; i < 26; i++)
                    {
                        int max = 55290;
                        if (i != 25) max = areacode[i + 1];
                        if (areacode[i] <= code && code < max)
                        {
                            return System.Text.Encoding.Default.GetString(new byte[] { (byte)(65 + i) });
                        }
                    }
                    return "?";
                }
                else
                    return cn;
            }
        }