给文本框加上提示效果

我们需要四个东西:图片、样式表、jquery库、页面代码

全部代码在这里:http://pan.baidu.com/share/link?shareid=200436&uk=2266385818

图片见demo里面:下面我们一个一个来:

1.css

/*=================全局样式【start】======================*/
*{
	scrollbar-face-color:#E6F2FD;
	scrollbar-highlight-color:#ffffff;
	scrollbar-shadow-color:#D6E4EF; 
	scrollbar-3dlight-color:#F1F9FF; 
	scrollbar-arrow-color:#006699; 
	scrollbar-track-color:#F1F9FF; 
	scrollbar-darkshadow-color:#F1F9FF;
}
body{
	margin:0px;
	color:#666;
	background-color:#FFF;
	font-family:Verdana, Geneva, sans-serif;
	font-size:12px;
}
form,ul,li{
	margin:0px;
	list-style-type:none;
	padding:0px;
}
table { empty-cells: show; border-collapse: collapse; }
a{
	color:#005eac;
	text-decoration:none;
}
a:visited,a:active{ color:#005eac; }
a:hover{ color:#ff5500; }
img{ border:0px; vertical-align:middle; }
/*=================全局样式【end】======================*/
.input{
	padding:0px 3px;
	border:1px solid #d1d1d1;
	background:url(input_bg.jpg) repeat-x;
	height:18px;
	line-height:18px;
	font-size:12px;
	color:#999;
}
.textarea{
	padding:3px;
	border:1px solid #d1d1d1;
	background:url(input_bg.jpg) repeat-x;
	font-size:12px;
	color:#999;
}
.focus{
	border:1px solid #FC0 !important;
	background:url(focus_bg.jpg) repeat-x !important;
	color:#333 !important;
}

/*提示文字样式*/
#HintMsg{
	width:271px;
	position:absolute;
	display:none;
}
#HintMsg .HintTop{
	height:9px;
	background:url(hintbg1.gif) no-repeat;
	overflow:hidden;
}
#HintMsg .HintInfo{
	padding:0 5px;
	border-left:1px solid #000;
	border-right:1px solid #000;
	background:#FFFFE1;
	line-height:1.5em;
}
#HintMsg .HintInfo b{
	display:block;
	margin-bottom:6px;
	padding-left:15px;
	background:url(hint.gif) left center no-repeat;
	height:13px;
	line-height:16px;
}
#HintMsg .HintInfo b span{
	display:block;
	float:right;
	text-indent:-9999px;
	background:url(close.gif) no-repeat;
	width:12px;
	height:12px;
	cursor:pointer;
}
#HintMsg .HintFooter{
	height:22px;
	background:url(hintbg2.gif) no-repeat;
}
/*设置提示样式*/

2.页面代码

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_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>文本框提示demo</title>
    <link href="images/example.css" rel="stylesheet" type="text/css" />    
</head>
<body>
    <form id="form1" runat="server">
    <div style=" margin:0 auto; width:600px;">
        <div style=" height:100px;"></div>
        <asp:TextBox ID="txtA" runat="server" CssClass="input" HintTitle="提示" HintInfo="这是提示的内容你懂的" />
        <br /><br />
        <asp:TextBox ID="txtB" runat="server" CssClass="textarea"  Height="130px" Width="500px" maxlength="250"
            HintTitle="标题你懂的" HintInfo="填写一些内容" TextMode="MultiLine" />
    </div>
    </form>
</body>
</html>


3.添加js到head里面

    <script src="js/jquery-1.4.1.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            $(".input,.textarea").focus(function () {
                $(this).addClass("focus");
            }).blur(function () {
                $(this).removeClass("focus");
            });

            $("[HintTitle],[HintInfo]").focus(function (event) {
                $("*").stop(); //停止所有正在运行的动画
                $("#HintMsg").remove();
                var HintHtml = "<ul id=\"HintMsg\"><li class=\"HintTop\"></li><li class=\"HintInfo\"><b>" + $(this).attr("HintTitle") + "</b>" + $(this).attr("HintInfo") + "</li><li class=\"HintFooter\"></li></ul>";
                var offset = $(this).offset(); //取得事件对象的位置
                $("body").append(HintHtml); //添加节点
                $("#HintMsg").fadeTo(0, 0.85);
                var HintHeight = $("#HintMsg").height(); //取得容器高度
                $("#HintMsg").css({ "top": offset.top - HintHeight + "px", "left": offset.left + "px" }).fadeIn(500);
            }).blur(function (event) {
                $("#HintMsg").remove();
            });
        });
    </script>

效果如下:

总结一下,这里主要就是一个jq获取对象的位置,然后添加一个节点

Ajax模仿google提示输入框 使用说明 v1.8 本程序由飞飞asp乐园编写 ************************************************* 特别感谢: 一杯白开水 网友 的帮助 版本所提的修改建议 ************************************************* 飞飞Asp乐园 www.ffasp.com QQ:276230416 QQ:72840059 ********************************************* 程序介绍: 本程序官网演示地址:http://www.ffasp.com/content.asp?newsid=1376 转载请注明出处 此小程序是模仿Google(sgguest)输入提示框所编写 亦可用于用户注册邮箱时的提示 此程序使用方便简单、易用灵活 且不限Asp、php、net 更新说明: 1.支持xhtml 2.兼容IE6,IE7,FF 3.支持input显示与value分离【以隐藏域方式提交数据】 4.支持下拉框按钮 5.支持显示结果数量 6.可以一个页面多次使用 7.模拟下拉框不会被select遮挡 8.调用更方便(内核已改为jq插件) 9.皮肤修改方便 ,外置的css样式文件,带有注释说明,任意修改 10.支持键盘方向键按住不放选择 11.解决了延时卡死的现象 12.解决了在有滚动条时,ie6下被表单遮挡的问题 13.支持回调函数。当该插件执行完毕时,执行另外一个指定函数 ######V1.7解决问题############ 14.可以自己设置提示框的长度 15.解决了无法获取用户填写默认值的问题 16.当输入框失去焦点时,提示框会自动隐藏 ######V1.8解决问题############ 17.解决了鼠标无法选择的问题 ****************************************************************** 文件使用说明: 在需要使用的页面首先要引用2个js文件 <script src="jquery1.2.6.min.js"></script> <script src="search_suggest.js"></script> 此二文件必须放于调用函数之前 *****************************以下是调用示例*************************: var option = { inputName : "test2", inputText : "测试字符串4", inputValue: "我是值", inputlength:1, url : "search.asp", arrow :1, arrowUrl :"search.asp?aa=nowitest", zIndex:7, fns:function(){alert(3)} } $("#test").suggestShow(option) +++++++解释说明+++++++++++++++++++++++++++++++++++++++++++++++++++++++++ option:为参数设置对象。option内的所有参数可以省略 inputName 表单input的name.即 提交时获取input的name。也为search.asp页面获取input的name inputText inputName 所显示的数据 inputValue inputName 所提交的数据,当inputValue省略时,inputValue则与inputText相等 url 远程执行获取数据的url arrow 模仿select,使用下拉按钮。固定值。为1则显示下拉箭头 为0则不显示 arrowUrl 当arrow为1时 ,默认情况下点击下拉按钮所执行的远程搜索页面 zIndex z-index值 inputlength inputName中输入数据的最小长度 suggestWidth 提示框的长度 fns 当执行完该插件时,执行的回调函数 ************************************************************************ search.asp页面介绍: 该页面返回数据必须是xml格式,输出数据数据必须符合以下格式 <response value="1" result ="共2个结果">显示信息</response> 属性介绍: 1.value aa的value值,可以不填。不填value值则取"显示信息" 2.result 显示远程获取的统计结果,可以不填。 3.显示信息 即aa的显示值text值 ************************************************************************
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值