DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> jQuery入門知識 >> JQuery特效代碼 >> ASP.NET jQuery 實例1(在TextBox裡面創建一個默認提示)
ASP.NET jQuery 實例1(在TextBox裡面創建一個默認提示)
編輯:JQuery特效代碼     
當文本框獲得焦點,如果文本框內容跟提示內容一樣,提示內容會自然消失。
當文本框沒有任何值並失去焦點,文本框內容會重新生成默認提示。
為了實現上面的需求,代碼如下:
. 代碼如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Recipe1.aspx.cs" Inherits="Recipe1" %>
<!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>Recipe1</title>
<script src="Scripts/jquery-1.4.1-vsdoc.js" type="text/javascript"></script>
<style type="text/css">
.defaultText
{
font-style: italic;
color: #CCCCCC;
}
</style>
<script type="text/javascript">
$(document).ready(function () {
var searchBox = $("#<%=txtSearch.ClientID %>"); // 通過ClientID獲取服務器控件ID
searchBox.focus(function () {
if (searchBox.val() == this.title) { // TextBox控件ToolTip屬性轉換為Html為title屬性
searchBox.val("");
searchBox.removeClass("defaultText");
}
});
searchBox.blur(function () {
if (searchBox.val() == "") {
searchBox.val(this.title);
searchBox.addClass("defaultText");
}
});
searchBox.blur();
});
</script>
</head>
<body>
<form id="form1" runat="server">
<p>
</p>
<div align="center">
<fieldset style="width: 400px; height: 80px;">
<p>
<asp:TextBox ID="txtSearch" runat="server" Width="200px" CssClass="defaultText" ToolTip="請輸入搜索的關鍵字"></asp:TextBox>
<asp:Button ID="btnSearch" runat="server" Text="搜索" /></p>
</fieldset>
</div>
</form>
</body>
</html>

顯示效果:

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved