jQuery UI Autocomplete 实例

<script type="text/javascript">
    $(function () {
        $('#city_name').autocomplete({
//            max:5,
//            width:210,
//            scrollHeight:300,
            minLength:2,
            source:$.parseJSON($("#city_date").val()),
            select:function (e, ui) {
                $("#city_id").val(ui.item.value);
                $('#city_name').val(ui.item.label+",  "+ui.item.desc)
                return false
            },
            focus:function (e, ui) {
                $('#city_name').val(ui.item.label)
                return false
            }
        }).data("autocomplete")._renderItem = function (ul, item) {
            return $("<li></li>")
                    .data("item.autocomplete", item)
                    .append("<a style='margin-left: 2px;'><span>" + item.label + "</span><span style='margin-right: 2px; float:right; color:#08C;'>" + item.desc + "</span><a>")
                    .appendTo(ul);
        };
    });
</script>
 

相关推荐