jqueryui的autocomplete一个简单例子

来源:互联网 发布:查股网ddx日线数据 编辑:程序博客网 时间:2024/05/23 15:39


js部分:

<script>

    $(function() {
        //var mydata=[{"label": "abd", "value": "cnblogs"}, {"label": "acx", "value": "囧月"}];
        
        $( "#tags" ).autocomplete({
            source: function(request,response){
                $.ajax({
                    autoFocus:true,
                    url:"../GiveMyTip",
                    dataType:"json",
                    data:{
                        name:request.term
                    },
                    
                    success:function(data){
                        response(data);
                    }
                });
            }
        });
    });
    
    //进行表单的提交,并指定当前的iframe
    function togive() {
        var dept=$("#tags").val();
        var url="<%=basePath%>DeptAction?dept="+dept;
        $("#topingyin").attr("target","myiframe");
        $("#topingyin").attr("action",url).submit();

    }   

    </script>


Html部分:

 <div class="ui-widget" style ="width:290px;height:33px;float:left;">
                <label for="tags" style="line-height:33px; font-weight:400;">Tags: </label>
                <input id="tags" style="line-height:25px;">
                
                <div style="background-color:#CCC; float:right; width:76px;margin-top:3px; height:27px; line-height:28px; font-weight:400;">
                 <a target="myiframe" onClick="togive()">搜索</a>
                 <form id="topingyin" method="post" ></form>
                 </div>
                </div>


<div style="float:left; width:85%; height:768px;">
         <iframe  style="margin:o auto; width:100%; height:768px; margin:0 auto;" name="myiframe">
          hhhhhdhhd
         </iframe>
        </div>



jsp的后台部分:

public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");
        String name=request.getParameter("name");
        System.out.println(name);
        
        PrintWriter out=response.getWriter();
        List<String> list=new ArrayList<String>();
        for(ToolString e:py.testEnum(name)){
            list.add(e.getName());
        }
        StringBuilder strbulider=new StringBuilder();
        strbulider.append("[\"");
            for(int i=0;i<list.size();i++){
                strbulider.append(list.get(i));
                if(i!=list.size()-1){
                    strbulider.append("\",\"");
                }
            }
        strbulider.append("\"]");
        System.out.println(strbulider.toString());
        out.print(strbulider.toString());
    }


0 0
原创粉丝点击