表單JS彈出填寫提示效果代碼
更新時間:2011年04月16日 17:52:12 作者:
表單JS彈出填寫提示效果代碼,需要的朋友可以參考下。
HTML
<form id="form1" runat="server">
<div>
<div style="margin-top:100px">
<asp:TextBox ID="TextBox1" runat="server" HintTitle="增加的內容信息標題" HintInfo="控制在100個字數(shù)內,標題文本盡量不要太長。"></asp:TextBox></div>
</div>
</form>
頁面中的樣式
<style type="text/css">
.focus
{
border: 1px solid #FC0 !important;
background: url(Admin/Images/focus_bg.jpg) repeat-x !important;
color: #00F !important;
}
/*提示文字樣式*/
#HintMsg
{
width: 271px;
position: absolute;
display: none;
}
#HintMsg .HintTop
{
height: 9px;
background: url(Admin/Images/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(Admin/Images/hint.gif) left center no-repeat;
height: 13px;
line-height: 16px;
}
#HintMsg .HintInfo b span
{
display: block;
float: right;
text-indent: -9999px;
background: url(Admin/Images/close.gif) no-repeat;
width: 12px;
height: 12px;
cursor: pointer;
}
#HintMsg .HintFooter
{
height: 22px;
background: url(Admin/Images/hintbg2.gif) no-repeat;
}
</style>
關鍵JS
$(function() {
$(".input,.login_input,.textarea").focus(function() {
$(this).addClass("focus");
}).blur(function() {
$(this).removeClass("focus");
});
//輸入框提示,獲取擁有HintTitle,HintInfo屬性的對象
$("[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); //添加節(jié)點
$("#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(); //刪除UL
});
});
復制代碼 代碼如下:
<form id="form1" runat="server">
<div>
<div style="margin-top:100px">
<asp:TextBox ID="TextBox1" runat="server" HintTitle="增加的內容信息標題" HintInfo="控制在100個字數(shù)內,標題文本盡量不要太長。"></asp:TextBox></div>
</div>
</form>
頁面中的樣式
復制代碼 代碼如下:
<style type="text/css">
.focus
{
border: 1px solid #FC0 !important;
background: url(Admin/Images/focus_bg.jpg) repeat-x !important;
color: #00F !important;
}
/*提示文字樣式*/
#HintMsg
{
width: 271px;
position: absolute;
display: none;
}
#HintMsg .HintTop
{
height: 9px;
background: url(Admin/Images/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(Admin/Images/hint.gif) left center no-repeat;
height: 13px;
line-height: 16px;
}
#HintMsg .HintInfo b span
{
display: block;
float: right;
text-indent: -9999px;
background: url(Admin/Images/close.gif) no-repeat;
width: 12px;
height: 12px;
cursor: pointer;
}
#HintMsg .HintFooter
{
height: 22px;
background: url(Admin/Images/hintbg2.gif) no-repeat;
}
</style>
關鍵JS
復制代碼 代碼如下:
$(function() {
$(".input,.login_input,.textarea").focus(function() {
$(this).addClass("focus");
}).blur(function() {
$(this).removeClass("focus");
});
//輸入框提示,獲取擁有HintTitle,HintInfo屬性的對象
$("[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); //添加節(jié)點
$("#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(); //刪除UL
});
});
效果圖:
以上內容來子一個下載的網站,具體的名字忘記了....僅作參考
您可能感興趣的文章:
- 實用的JS表單驗證提示效果
- javascript寫的一個表單動態(tài)輸入提示的代碼
- js+css實現(xiàn)增加表單可用性之提示文字
- js下在password表單內顯示提示信息的解決辦法
- js實現(xiàn)表單檢測及表單提示的方法
- JavaScript DOM學習第八章 表單錯誤提示
- javascript中IE瀏覽器不支持NEW DATE()帶參數(shù)的解決方法
- IE8的JavaScript點擊事件(onclick)不兼容的解決方法
- 讓ie運行js時提示允許阻止內容運行的解決方法
- Javascript在IE下設置innerHTML時出現(xiàn)未知的運行時錯誤的解決方法
- JavaScript的常見兼容問題及相關解決方法(chrome/IE/firefox)
- IE瀏覽器下JS腳本提交表單后,不能自動提示問題解決方法
相關文章
在一個form用一個SUBMIT(或button)分別提交到兩個處理表單頁面的代碼
在一個form用一個SUBMIT(或button)分別提交到兩個處理表單頁面的代碼...2007-02-02