一、文本框中创建默认文本提示

通常用户在搜索内容时,在文本框输入内容前,文本框都会给出默认提示,提示用户输入正确的内容进行搜索。

当文本框获得焦点,如果文本框内容跟提示内容一样,提示内容会自然消失。

当文本框没有任何值并失去焦点,文本框内容会重新生成默认提示。

为了实现上面的需求,代码如下:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Web.Default" %>
 
<!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 runat="server">
    <title></title>
    <script src="jquery-1.8.2.min.js" type="text/javascript"></script>
    <link href="Base.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
        .text
        {
            border: #0a8fda solid 1px;
            color: #cccccc;
            font-style:italic;
            background: #fff url(img/input.gif);
            padding: 5px;
        }
        .text-focus
        {
            border: solid 1px #f50;
            background: #fff url(img/input.gif);
            padding: 5px;
        }
    </style>
    <script type="text/javascript">
        $(document).ready(function () {
            var txtSearch = $("#<%=txtSearch.ClientID%>");
 
            $("#txtSearch").focus(function () {
                if (txtSearch.val() == this.title) {
                    txtSearch.val("");
 
                    this.className = "text-focus";
                }
            });
 
            $("#txtSearch").blur(function () {
 
                if (txtSearch.val() == "") {
                    txtSearch.val(this.title);
                    this.className = "text";
                }
            });
            txtSearch.blur();
        });
    
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div style="margin: 100px auto; width: 400px; height: 80px;border: solid 1px #0a8fda;">
        <p style="text-align:center;">
            <asp:TextBox ID="txtSearch" runat="server" Width="200px" class="text" ToolTip="请输入搜索的关键字"></asp:TextBox>
            <asp:Button ID="btnSearch" runat="server" Text="搜索" class="button blue" />
        </p>
    </div>
    </form>
</body>
</html>

最新文章

  1. js日期重写
  2. thinkphp里的session、cookie方法
  3. 使用PDF.JS在线查看PDF
  4. 【iCore3 双核心板】例程十九:USBD_MSC实验——虚拟U盘
  5. Count Color(线段树+位运算 POJ2777)
  6. MySQL中DATE_FORMATE函数内置字符集解析
  7. PERCONA-TOOLKIT 工具的安装与使用2
  8. iOS圆盘转动引导图的简单实现
  9. uva 10069 Distinct Subsequences(高精度 + DP求解子串个数)
  10. JavaScript 中的内存和性能、模拟事件(读书笔记思维导图)
  11. 使用原始XML资源——使用原始XML文件
  12. [SCOI2011] 糖果
  13. 面向对象之七大基本原则(javaScript)
  14. Java之static作用的全方位总结
  15. 第26月第7天 mac如何matplotlib中文乱码问题
  16. 理解OAuth 2.0 (摘自阮一峰网络日志)
  17. springboot-12-自定义拦截器的配置interceptor
  18. 【1】Singleton模式(单例模式)
  19. 《OpenCL异构并行编程实战》第十二至十四章
  20. c# 有无符号值进一步了解

热门文章

  1. HDU 3336 Count the string
  2. linux c in common use function reference manual
  3. Asp.Net MVC4.0 官方教程 入门指南之五--控制器访问模型数据
  4. Foundation 框架 NSString常用总结
  5. 获取当前WEB应用全路径
  6. visual studio 2013 使用IIS Express附加调试MVC5
  7. 青蛙跳台阶问题——剑指offer
  8. Lucence.net索引技术 一
  9. hive premanent udf 发布...
  10. Linux 网络编程: daytime Service