文本框下拉自動提示功能

一、首先引用:
<link href="jquery.autocomplete.css" rel="stylesheet" type="text/css" />
<script src="jquery.autocomplete.min.js" type="text/javascript"></script>

二、html代碼:
<label>HR Owner:</label>
  <input id='hr_Owener' validate="{required:true}" type="text"/>
  <input id='hr_Owener_EmpNO_EmpName' type="hidden" />

$(document).ready(function() {

       //初始化hrOwener  開始(zhaolei  2013-9-26 新增)
        $.ajax({
            type: "POST",
            url: '/Recruiting/GetHrOwener',  //這裏能夠是控制器裏的方法,也能夠是定義到頁面,好比:'/Recruiting/GetHrOwener.aspx'
            //dataType: "json",
            success: function(result) {
                set = JSON.parse(result);
                $('#hr_Owener').bind("input.autocomplete", function() {
                    $(this).trigger('keydown.autocomplete');
                });
                $('#hr_Owener').autocomplete(set, {
                    minChars: 0,
                    max: 9999,
                    autoFill: false,
                    matchContains: true,
                    width: 180,
                    scrollHeight: 220,
                    formatItem: function(data) {
                        return (data.DisplayName + '[' + data.EmployeeNo + ']');
                    },
                    formatMatch: function(row, i, max) {
                        return row.DisplayName + row.EmployeeNo + row.UserName;
                    },
                    formatResult: function(row) {
                        return row.DisplayName;
                    }
                }).result(function(event, data, formatted) {
                    $('#hr_Owener_EmpNO_EmpName').val(data.EmployeeNo + "_" + data.DisplayName); //將HROwenerID 和HROwenerName拼接
                });
            }
        });
        //初始化hrOwener  結束
}javascript

三、效果以下:css

相關文章
相關標籤/搜索