jquery-autocomplete配置:
<script type="text/javascript" src="/js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="/js/jquery.autocomplete.min.js"></script>
<link rel="Stylesheet" href="/js/jquery.autocomplete.css" />
下面是JS代码片段:
<script type="text/javascript"> $(document).ready(function() { $("#To_City").autocomplete(<s:property value="toCityJsonArray" escape="false"/>, { minChars: 0, matchContains: true, 130, formatItem: formatToCity, formatResult: toCityFormatResult, max: 15, scroll: true, scrollHeight: 300 }); }); function formatToCity(toCity) { return "<span style='70px'>" + toCity.To_City + "</span>\t" + toCity.To_City_Chn_Nm ; } function toCityFormatResult(toCity) { return toCity.To_City_Chn_Nm; }
</script>
其中,toCityJsonArray 是JSONArray类型的json, 格式为:[{To_City:"SHA",To_City_Chn_Nm:"上海"},{To_City:"CTU",To_City_Chn_Nm:"成都"}]
下面是html代码片段:
<input type="text" name="To_City" id="To_City" size = "10" value="<s:property value="To_City" />"/>