asp.net使用jquery實(shí)現(xiàn)搜索框默認(rèn)提示功能
文本框中創(chuàng)建默認(rèn)文本提示
通常用戶在搜索內(nèi)容時(shí),在文本框輸入內(nèi)容前,文本框都會(huì)給出默認(rèn)提示,提示用戶輸入正確的內(nèi)容進(jìn)行搜索。
當(dāng)文本框獲得焦點(diǎn),如果文本框內(nèi)容跟提示內(nèi)容一樣,提示內(nèi)容會(huì)自然消失。
當(dāng)文本框沒有任何值并失去焦點(diǎn),文本框內(nèi)容會(huì)重新生成默認(rèn)提示。
為了實(shí)現(xiàn)上面的需求,代碼如下:
<%@ 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="請(qǐng)輸入搜索的關(guān)鍵字"></asp:TextBox>
<asp:Button ID="btnSearch" runat="server" Text="搜索" class="button blue" />
</p>
</div>
</form>
</body>
</html>
- 讓input框?qū)崿F(xiàn)類似百度的搜索提示(基于jquery事件監(jiān)聽)
- Jquery實(shí)現(xiàn)搜索框提示功能示例代碼
- jquery+php實(shí)現(xiàn)搜索框自動(dòng)提示
- jquery 模擬類搜索框自動(dòng)完成搜索提示功能(改進(jìn))
- jQuery 插件仿百度搜索框智能提示(帶Value值)
- 利用JQuery為搜索欄增加tag提示
- Jquery模仿Baidu、Google搜索時(shí)自動(dòng)補(bǔ)充搜索結(jié)果提示
- jquery 關(guān)鍵字“拖曳搜索”之“拖曳”以及 圖片“提示自適應(yīng)放大”效果 的實(shí)現(xiàn)
- jquery實(shí)現(xiàn)非疊加式的搜索框提示效果
- 基于jQueryUI和Corethink實(shí)現(xiàn)百度的搜索提示功能
- jQuery實(shí)現(xiàn)模擬搜索引擎的智能提示功能簡(jiǎn)單示例
相關(guān)文章
asp.net(C#)中上傳大文件的幾中常見應(yīng)用方法
最近博客需要做一個(gè)文件上下載功能,我從網(wǎng)上找了點(diǎn)資料,整理了下希望對(duì)大家有幫助!2008-11-11
asp.net文件上傳帶進(jìn)度條實(shí)現(xiàn)案例(多種風(fēng)格)
這篇文章主要講解了asp.net文件上傳帶進(jìn)度條實(shí)現(xiàn)案例,有不同風(fēng)格的進(jìn)度條,一定有一款最適合你,感興趣的小伙伴們可以參考一下2015-09-09
asp.net簡(jiǎn)單頁面控件賦值實(shí)現(xiàn)方法
這篇文章主要介紹了asp.net簡(jiǎn)單頁面控件賦值實(shí)現(xiàn)方法,涉及數(shù)據(jù)庫的查詢及頁面控件元素賦值操作相關(guān)技巧,需要的朋友可以參考下2016-07-07
ASP.NET 獲取存儲(chǔ)過程返回值的實(shí)現(xiàn)代碼
ASP.NET 獲取存儲(chǔ)過程返回值的實(shí)現(xiàn)代碼,需要的朋友可以參考下。2011-12-12
Asp.net 彈出對(duì)話框基類(輸出alet警告框)
asp.net輸出alert警告框2008-11-11

