sp代碼:html
<html:text
property="startBook.brandName"
style="width:210px;" styleId="brand" />
<div id="brandlist" style="overflow: auto; display:none; width:210px; height:150px; position: absolute; text-align:left; background-color: white; border: solid thin #000;">
</div>jquery
jquery:ajax
$(function(){
$("#brand").keyup(function(){
$("#brandlist").show();
var brand=$(this).val();
$.ajax({
url : "startUpBook.go?method=brandlist",
type : "POST",
cache : false,
data : "brand="+brand,
error : function() {
alert("數據加載異常")
},
success : function(data) {
$("#brandlist").html(data);
}
});
})});sql
action:ide
String brand=request.getParameter("brand").toString().trim();
System.out.print(brand);
String brandl=startBook.brandlist(brand);
System.out.print(brandl);
request.setAttribute("data", brandl);
response.setContentType("textml;charset=UTF-8");
response.setCharacterEncoding("UTF-8");
response.getWriter().print(brandl);
return null;優化
IBAS:this
public String brandlist(String brand) {
String brandlisturl="";
List list = new ArrayList();
String name=brand;
list = this.queryList(name, "XNN_sql_Product.queryBrandlist");
for(int i=0;i<list.size();i++)
{ CBrand cbrand=(CBrand)list.get(i);
brandlisturl=brandlisturl+"<p onclick="+"\"$('#brand').val($(this).html());$('#brandlist').hide();\">"+cbrand.getName()+"</p>";
}
return brandlisturl;url
SQL:orm
SELECT DISTINCT(name) `name` from c_brand WHERE 1=1
<isNotEmpty prepend=" and ">
name like
CONCAT('%', '$name$', '%')
</isNotEmpty>
and name is not nullhtm
效果實現中遇到問題:
SQL 傳參數沒有加‘號,查詢出錯
界面結果沒法實現點擊後自動到輸入框。
解決辦法 在查詢階段把JS事件拼進去。(不足代碼不簡介,拼方法進去,調用不成功)
JQUERY裏KEYUP,blur事件在同一級,沒法實現再次查詢後的結果自動填充
後期時間容許再作代碼優化