zoukankan      html  css  js  c++  java
  • jquery-ui-custom autocomplete

     //jsp
    <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
    <%
        String path = request.getContextPath();
        String basePath = request.getScheme() + "://"+ request.getServerName() + ":" + request.getServerPort()+ path + "/";
    %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
        <head>
            <base href="<%=basePath%>">
     
            <title>autocomplete</title>
     
            <meta http-equiv="pragma" content="no-cache">
            <meta http-equiv="cache-control" content="no-cache">
            <meta http-equiv="expires" content="0">
            <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
            <meta http-equiv="description" content="This is my page"> 
      
            <link href="<%=basePath%>js/autocomplete/jquery-ui-1.10.3.custom.css" rel="stylesheet">
            <script src="<%=basePath%>js/jquery-1.7.2.min.js"></script>
            <script src="<%=basePath%>js/autocomplete/jquery-ui-1.10.3.custom.js"></script>
        <script>
            $(function(){
                $( "#autocomplete" ).autocomplete({
                    minLength: 1,//最少输入1个字符才执行
                    source: 'autocomplete.action'
                });
            })
        </script>
        </head>
        <style>
            body {
                font: 62.5% "Trebuchet MS", sans-serif;
                margin: 50px;
            }
        </style>
        <body>
            <h2 style="margin-top: 2em;">
                Autocomplete
            </h2>
            <div>
                <input id="autocomplete" title="type &quot;a&quot;">
            </div>
        </body>
    </html>  
    //struts.xml
    <action name="autocomplete" class="com.test.action.testAction" method="autocomplete"></action> 

    //java
    public String autocomplete() throws Exception{
             
            String[] temp = "align,both,card,dream,error,fail,gson,hello,invaid,job,kill".split(",");
            String name = "[";
            for(int i=0;i<temp.length;i++){
                if(temp[i].indexOf(term)!=-1){
                    name += """+temp[i]+"",";
                }
            }
            if(name.length() > 1)
                name = name.substring(0,name.length()-1);
            name+="]";
             
            System.out.println(name);
             
            HttpServletResponse res = ServletActionContext.getResponse();
            PrintWriter pw = res.getWriter();
            pw.write(name);
            pw.flush();
            pw.close();
             
            return null;
        } 

  • 相关阅读:
    CentOS7搭建FastDFS V5.11分布式文件系统(二)
    CentOS7搭建FastDFS V5.11分布式文件系统(一)
    JRebel最新破解激活版(IDEA自动部署插件)
    idea常用插件
    idea安装完成后要做的几件事(设置字体、编码、行号)
    IDEA修改Maven全局配置
    IDEA打开光标是粗黑色,backspace键、insert键点击无效的解决办法
    Hadoop build error java.lang.NoClassDefFoundError: org/sonatype/aether/graph/DependencyFilter
    Golang项目目录结构组织
    再看GOPATH
  • 原文地址:https://www.cnblogs.com/holdon521/p/4105784.html
Copyright © 2011-2022 走看看