国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

asp.net使用jquery實現搜索框默認提示功能

2020-01-17 23:35:59
字體:
來源:轉載
供稿:網友

文本框中創建默認文本提示

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

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

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

為了實現上面的需求,代碼如下:

復制代碼 代碼如下:

<%@ 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>

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 赞皇县| 韶山市| 灵璧县| 左云县| 儋州市| 克什克腾旗| 四子王旗| 阿坝| 永平县| 岑溪市| 科尔| 永胜县| 溧阳市| 神池县| 镇原县| 晋江市| 阿城市| 商河县| 沭阳县| 镇江市| 萍乡市| 南京市| 黄山市| 宜丰县| 广汉市| 波密县| 长白| 康定县| 临猗县| 谢通门县| 宝兴县| 罗源县| 大洼县| 昆明市| 临沧市| 响水县| 灵石县| 新沂市| 景东| 旬邑县| 盐城市|