/*==========加载时执行的语句==========*/ $(function () { $.getJSON("JsonHandler.ashx", {}, function (json) { initAutoComplete(json); }) });
function initAutoComplete(json) { $("#suggest1").autocomplete(json, { minChars: 1, matchCase: false, //不区分大小写"JsonHandler.ashx" autoFill: false, max: 10, formatItem: function (row, i, max, term) { // row = eval("(" + row + ")"); "JsonHandler.ashx" var v = $("#suggest1").val(); return row.name + " (" + row.code + ")"; if (row.code.indexOf(v) == 0 || row.spell.indexOf(v) == 0) { return row.name + " (" + row.code + ")"; } else return false; }, formatMatch: function (row, i, max) { // row = eval("(" + row + ")"); return row.name + " (" + row.code + ")"; }, formatResult: function (row) { // row = eval("(" + row + ")"); return row.name + " (" + row.code + ")"; }, reasultSearch: function (row, v)//本场数据自定义查询语法 注意这是我自己新加的事件 { // row = eval("(" + row + ")"); //自定义在code或spell中匹配 if (row.data.code.indexOf(v) >= 0 || row.data.spell.indexOf(v) >= 0||row.data.name.indexOf(v)>=0 ) { return row; } else return false; } }); }