惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 【当耐特】
Stack Overflow Blog
Stack Overflow Blog
V
Visual Studio Blog
小众软件
小众软件
The Cloudflare Blog
T
Tailwind CSS Blog
Apple Machine Learning Research
Apple Machine Learning Research
爱范儿
爱范儿
美团技术团队
WordPress大学
WordPress大学
罗磊的独立博客
Microsoft Azure Blog
Microsoft Azure Blog
A
About on SuperTechFans
Last Week in AI
Last Week in AI
月光博客
月光博客
博客园 - Franky
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
G
Google Developers Blog
GbyAI
GbyAI
B
Blog
大猫的无限游戏
大猫的无限游戏
博客园 - 聂微东
Hugging Face - Blog
Hugging Face - Blog
博客园 - 叶小钗

博客园 - 迷梦江南

DB2问题记录本 AS3无缝循环播放FLV flex开发零碎笔记,随时补充 AS3淡入淡出类 JQuey练习一 转“大型网站架构演变和知识体系” 转“大型高并发高负载网站的系统架构 ” 转“经验分享:大型高并发高负载网站的系统架构 ” 转“关于平台研发的一些想法” 转“国内图片网站Yupoo的架构” mootools 1-4 ajax C#测试代码段运行速度 - 迷梦江南 - 博客园 javascript放大图片 - 迷梦江南 - 博客园 javascript网站导航栏 - 迷梦江南 - 博客园 QQ在线状态接口 - 迷梦江南 - 博客园 (转)Javascript在IE与Firefox下的差异 WebApplication与Profile购物车 网站发布后出现的两个问题 ASP.NET查看本地磁盘下的子目录和文件信息
mootools实现搜索提示文本框修正版
迷梦江南 · 2007-12-07 · via 博客园 - 迷梦江南

以前做了个提示文本框的示例,里面有很多不必要的东西,现在我修改了下,JS代码比以前简单了。

HTML

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="NewAjaxTextBox.aspx.cs" Inherits="NewAjaxTextBox" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head id="Head1" runat="server">

    <title>无标题页</title>

    <link href="AjaxText.css" rel="stylesheet" type="text/css" />

    <script type="text/javascript" src="mootools-release-1.11.js"></script>

    <script type="text/javascript">

        function getMsg(obj){

            $("ajaxtextbox").value=obj.innerHTML;

            $("msgdiv").innerHTML="";

            $("msgdiv").className="display1";

        }

        window.addEvent('domready',function(){

                $('ajaxtextbox').addEvent('keyup',function(e){

                    if($('ajaxtextbox').value==''){

                        return;

                    }

                    var url="NewAjaxTextBox.aspx?value="+ escape($('ajaxtextbox').value);

                    new Ajax(url,{method:'post',

                        onComplete:function(){

                            $("msgdiv").innerHTML=this.response.text;

                            if(this.response.text!=''){

                                $("msgdiv").className="display2";

                            }

                        }

                    }).request();

            });

        });

    </script>

</head>

<body>

    <input type="text" id="ajaxtextbox" class="text" runat="server" /><br />

    <div id="msgdiv" class="display1"  >

    </div>

</body>

</html>

CS

using System;

using System.Data;

using System.Configuration;

using System.Collections;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

using System.Text;

public partial class NewAjaxTextBox : System.Web.UI.Page

{

    public static DataTable dt = new DataTable();

    protected void Page_Load(object sender, EventArgs e)

    {

        if (dt.Rows.Count < 1)

        {

            dt.Columns.Add("content");

            for (int i = 0; i < 3; i++)

            {

                DataRow dr = dt.NewRow();

                dr["content"] = "呵呵" + i.ToString();

                dt.Rows.Add(dr);

            }

            for (int i = 0; i < 3; i++)

            {

                DataRow dr = dt.NewRow();

                dr["content"] = "哈哈" + i.ToString();

                dt.Rows.Add(dr);

            }

        }

        if (!String.IsNullOrEmpty(Request["value"]))

        {

            Seach(Request["value"]);

        }

    }

    protected void Seach(string value)

    {

        StringBuilder sb = new StringBuilder();

        for (int i = 0; i < dt.Rows.Count; i++)

        {

            string content = dt.Rows[i]["content"].ToString();
            if (content.IndexOf(value.Trim())>0||content.StartsWith(value.Trim())||content.EndsWith(value.Trim()))

            {

                string id = "dv" + i.ToString();

                sb.AppendFormat("<div id=\"{0}\"  style=\"width:170px; cursor:pointer;\"  ><a href=\"javascript:void(null);\"  onclick=\"getMsg(this)\" >{1}</a></div>", id, dt.Rows[i]["content"].ToString());

            }

        }

        Response.Clear();

        Response.Write(sb);

        Response.End();

    }

}

AjaxText.css

.text{ width:200px; font-size:12px; left:0px;}

.display1{ width:200px; left:1px;}

.display2{ width:200px; border: solid  1px black;  left:1px;}

a:link

{

     color: #000000;

     text-decoration: none;

}

a:visited

{

     color: #0000FF;

     text-decoration: none;

}

a:hover

{

     color: #FF0000;

     text-decoration: underline;

}

运行效果: