var searchtext = $("#xmmc", dialog); var $autocomplete = $("<ul class=‘autocomplete‘></ul>").hide().insertAfter(searchtext); searchtext.keyup(function () { var stext = searchtext.attr("value"); $.ajax({ url: ‘/dataAjax.aspx‘, data: ‘action=xmlist&text=‘ + URLencode(stext) + ‘&time=‘ + new Date().getTime(), dataType: "text", async: false, success: function (text) { $autocomplete.empty(); if (text != "[{}]") { var dataObj = eval("(" + text + ")"); $.each(dataObj, function (idx, item) { $("<li class=\‘autocomplete_li\‘></li>").text(item.xmmc).appendTo($autocomplete) .mouseover(function () { $(this).css("background", "#e4f5ff"); }).mouseout(function () { $(this).css("background", "white"); }) .click(function () { searchtext.attr("value", item.xmmc); $autocomplete.hide(); }); }); } $autocomplete.show(); }, error: function (XMLHttpRequest, textStatus, errorThrown) { alert(XMLHttpRequest.status); alert(XMLHttpRequest.readyState); alert(textStatus); } }); }).blur(function () { setTimeout(function () { $autocomplete.hide(); }, 500); });
时间: 2024-10-15 05:38:47