zoukankan      html  css  js  c++  java
  • 智能搜索

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>
    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <title></title>
        <script type="text/javascript" >
            function FunSelect() {
                var word = document.getElementById("city").value;
                if (word != "") {
                    // alert("1");
                    var xmlhttp = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
                    //  alert("2");
                    xmlhttp.open("GET", "Handler1.ashx?word=" + encodeURIComponent(word), true);
                    //  alert("3")
                    xmlhttp.send(null);
                    //   alert("4");
                    xmlhttp.onreadystatechange = function () {
                        if (xmlhttp.readyState == 4) {
                           // alert(xmlhttp.responseText);
                           document.getElementById("myText").innerHTML = xmlhttp.responseText;
                          
                        }
                    }
                }
              
            }
            function FunGetValue(s) {
                document.getElementById("city").value = s;
                document.getElementById("myText").innerHTML = "";
            }
        </script>
        <style>
            li:hover {
                background-color:#b6ff00;
            }
            #divFeild {
                500px;
                height:20px;
                position:relative;
            }
            #wordDiv {
                position:absolute;
                left:20px;
                top:20px;
            }
        </style>
    </head>
    <body>
        <form id="form1" runat="server">
            <div id="divFeild">
                <input type="text" id="city" name="city"    onkeyup ="FunSelect()" /><br />
                <div id="wordDiv"> <ul id="myText"></ul></div>
            
            </div>
            <p>ssssssssssssssssssssssss</p>
            <p>ssssssssssssssssssssssss</p>
            <p>ssssssssssssssssssssssss</p>
        </form>
    </body>
    </html>
    =======================================================================using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    namespace WebApplication1
    {
        /// <summary>
        /// Handler1 的摘要说明
        /// </summary>
        public class Handler1 : IHttpHandler
        {
            public void ProcessRequest(HttpContext context)
            {
                List<string> stringList = new List<string>() { 
                   "湖北省","湖北省1","湖北省2","湖南省","河南省","河北省"
                };
                var word =context. Request.QueryString["word"];
                string result = "";
                foreach (string s in stringList)
                {
                    if (s.Contains(word))
                    {
                        //result +="<li style='list-style-type:none;' onclick='FunGetValue('"+s+"')'>"+ s+"</li>";
                        result += "<li style='list-style-type:none;' onclick='FunGetValue(this.innerText)'>" + s + "</li>";
                    }
                    // FunGetValue( '湖北省1')
                }
                context.Response.Write(result);
            }
            public bool IsReusable
            {
                get
                {
                    return false;
                }
            }
        }
    }
  • 相关阅读:
    Invalid CSRF Token 'null' was found on the request parameter '_csrf' or header 'X-CSRF-TOKEN'.
    Qt 下快速读写Excel指南(尘中远)
    QT 那些事
    安卓环境下,通过QT调用jar包
    android使用C/C++调用SO库
    雷军曾定下目标,2017年将聚焦5大核心战略,分别是:黑科技、新零售、国际化、人工智能和互联网金融五大部分
    Maven和Gradle
    链接生成接口
    孤儿进程和僵尸进程
    Case when 的使用方法
  • 原文地址:https://www.cnblogs.com/blogLYF/p/5653997.html
Copyright © 2011-2022 走看看