java ajax输入框自动提示

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事件在同一级,没法实现再次查询后的结果自动填充

后期时间容许再作代码优化

相关文章
相关标签/搜索