asp.net使用jquery实现搜索框默认提示功能
2014-01-13 11:39
756 查看
文本框中创建默认文本提示
通常用户在搜索内容时,在文本框输入内容前,文本框都会给出默认提示,提示用户输入正确的内容进行搜索。
当文本框获得焦点,如果文本框内容跟提示内容一样,提示内容会自然消失。
当文本框没有任何值并失去焦点,文本框内容会重新生成默认提示。
为了实现上面的需求,代码如下:
复制代码 代码如下:<%@ 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>
您可能感兴趣的文章:
相关文章推荐
- asp.net使用jquery实现搜索框默认提示功能
- 使用FlexBox和Json实现类似ComboBox(类似Google的输入提示和自动)功能-基于JQuery-ASP.NET
- ASP.NET JQuery 随笔-搜索框默认提示
- ASP.NET jQuery 实例12 通过使用jQuery validation插件简单实现用户注册页面验证功能
- 如何在asp.net中用jQuery实现便捷的提示功能和表单验证功能
- ASP.NET jQuery 实例12 通过使用jQuery validation插件简单实现用户注册页面验证功能
- ASP.NET jQuery 实例11 通过使用jQuery validation插件简单实现用户登录页面验证功能
- ASP.NET jQuery 随笔 使用allValidator插件简单实现客户端验证功能
- 如何在asp.net中用jQuery实现便捷的提示功能和表单验证功能-S.Sams
- ASP.NET jQuery 实例11 通过使用jQuery validation插件简单实现用户登录页面验证功能
- ASP.NET jQuery 食谱12 (通过使用jQuery validation插件简单实现用户注册页面验证功能)
- ASP.NET jQuery 食谱25 (使用jQuery UI的Autocomplete方法实现文本框的自动搜索填充功能)
- ASP.NET jQuery 食谱11 (通过使用jQuery validation插件简单实现用户登录页面验证功能)
- 如何在asp.net中用jQuery实现便捷的提示功能和表单验证功能
- ASP.NET jQuery 随笔 使用jQuery UI的Autocomplete方法实现文本框的自动搜索填充功能
- 如何在asp.net中用jQuery实现便捷的提示功能和表单验证功能
- 记录:asp.net mvc 中 使用 jquery 实现html5 实现placeholder 密码框 提示兼容password IE6
- asp.net下使用jQuery.AutoComplete完成仿淘宝商品搜索自动完成功能(改进了键盘上下选择体验)
- asp.net 使用NPOI实现导出Excel功能
- 使用jquery+ajax+php实现搜索框的功能