<script src="JS/jquery-1.4.2.js"></script>
<script src="JS/jquery.ui.core.js"></script>
<script src="JS/jquery.ui.position.js"></script>
<script src="JS/jquery.ui.widget.js"></script>
<script src="JS/jquery.ui.autocomplete.js"></script>
<link href="Themes/excite-bike/jquery-ui-1.9.0.custom.css" rel="stylesheet" />
<script type="text/javascript">
//附带的资源包,请到我的资源页去下载。
//请注意,ashx文件要放到JQueryComplete目录下
//导入顺序要跟文章相同
$(document).ready(function ()
{
$.ajax(
{
type: "post",
url: "KeyValueHandler.ashx",
dataType: "text",
success: function (data) {
pArray = $.parseJSON(data);
},
complete: function () {
$("#txtCitys").autocomplete({
source: pArray,
select: function (event, ui) {
//$("#txtCitys").val(ui.item.value);
$("#txtCitys").val(ui.item.label);
event.preventDefault();
}
});
$("#txtCitys").data("autocomplete")._renderItem = function (ul, item) {
return $("<li></li>")
.data("item.autocomplete", item)
.append("<a><table style='width:300;'> <tr> <td align='left'>" + item.label + "</td> <td align='right' style='color:green;'>" + item.value + "</td> </tr> </table></a>")
.appendTo(ul);
};
}
});
});
</script>
<body>
<input type="text" id="txtCitys" />
</body>