欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

asp.net使用jquery實現(xiàn)搜索框默認提示功能

 更新時間:2014年01月13日 11:39:43   作者:  
這篇文章主要介紹了asp.net使用jquery實現(xiàn)搜索框默認提示功能,大家參考使用吧

文本框中創(chuàng)建默認文本提示

通常用戶在搜索內(nèi)容時,在文本框輸入內(nèi)容前,文本框都會給出默認提示,提示用戶輸入正確的內(nèi)容進行搜索。

當文本框獲得焦點,如果文本框內(nèi)容跟提示內(nèi)容一樣,提示內(nèi)容會自然消失。

當文本框沒有任何值并失去焦點,文本框內(nèi)容會重新生成默認提示。

為了實現(xiàn)上面的需求,代碼如下:

復(fù)制代碼 代碼如下:

<%@ 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="請輸入搜索的關(guān)鍵字"></asp:TextBox>
            <asp:Button ID="btnSearch" runat="server" Text="搜索" class="button blue" />
        </p>
    </div>
    </form>
</body>
</html>

相關(guān)文章

最新評論