標籤:html nbsp map min orm 擷取 eva ack span
前台代碼
- <!DOCTYPE html>
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
- <title></title>
- <script src="jquery-1.10.2.min.js"></script>
- <link href="jquery-ui-1.12.1.custom/jquery-ui-1.12.1.custom/jquery-ui.css" rel="stylesheet" /> // 需要引的檔案
- <script src="jquery-ui-1.12.1.custom/jquery-ui-1.12.1.custom/jquery-ui.min.js"></script>
- </head>
- <body>
- <form id="form1" runat="server">
- <div>
- <input type="text" id="ado"/> // 文字框
- </div>
- </form>
- </body>
- <script type="text/javascript">
- $(function () {
- $("#ado").autocomplete({
- minLength: 1,
- // 通過函數來擷取並處理資料來源
- source: function (request, response) { // 這裡的request代表需要傳的東西,response是為了將資料展示給autocomplete
- $.post("hander.ashx", { data: request.term }, function (msg) { // 這裡ajax非同步請求資料返回一個json串
- var dd = eval("(" + msg + ")"); // 這裡將json字串裝換成json對象
- var arry = new Array(); //聲明了一個數組
- $.each(dd.data, function (i, list) { //遍曆json對象把json裡的資料添加到數組裡
- arry.push(list.Cname)
- });
- response($.map(arry, function (item) { return { value: item } })); //把數群組轉換成 value:item 格式,然後給response展示出來
- });
- }
- });
- });
- </script>
- </html>
至於獲後台資料就不寫了,你們自己寫吧!
C# autocomplete