ASP.NET에서 TextBox에 onfocus 이벤트와 onblur 이벤트를 적용하기 위한 예제입니다.
1. aspx 페이지 소스 <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <script type="text/javascript"> function LoginFocus(ID, strID) { if(ID.value == strID) ID.value = ''; } function LoginBlur(ID, strID) { if(ID.value == '') ID.value = strID; } </script> </head> <body> <form id="form1" runat="server"> <div> <asp:TextBox ID="TextBox1" runat="server">아이디</asp:TextBox> </div> </form> </body> </html>
2. Page_Load 함수 내용
protected void Page_Load(object sender, EventArgs e) {
string strID = "아이디"; TextBox1.Attributes.Add("onfocus", "LoginFocus(this, '" + strID + "');"); TextBox1.Attributes.Add("onblur", "LoginBlur(this, '" + strID + "');");
} |
|
|