我现在想在文本框获得焦点的时候去触发一个事件.
可是ASP.NET里文本框没有焦点事件.
假设当TEXT1获得焦点的时候.
让Lable1的背景色改变。
如何实现?
<HTML>
<HEAD>
<SCRIPT ID=clientEventHandlersJS LANGUAGE=javascript>
<!--
function text1_onfocus() {
window.text1.style.backgroundColor = "#ff0000";
}
//-->
</SCRIPT>
</HEAD>
<BODY>
<P><INPUT id=text1 name=text1 LANGUAGE=javascript οnfοcus="return text1_onfocus()"></P>
</BODY>
</HTML>
<asp:TextBox id=txt_Test runat=Server></asp:TextBox>
在后台代码里
if(!Page.IsPostBack)
{
txt_Test.Attribute.Add("onfocus","return text1_onfocus()")
}
这样写:
Me.TextBox1.Attributes.Add("onfocus", "window.Label1.style.backgroundColor ='#336699';")
C#
this.TextBox1.Attributes.add("onfocus", "window.Label1.style.backgroundColor='#336699';");
离开那就是onblue了.
this.TextBox1.Attributes.add("onblue", "window.Label1.style.backgroundColor='#000000';");