demoshop

demo, trying to be the best_

有時後會很習慣在文字方塊輸入完畢後就按ENTER去執行或是去確定,這篇是利用Java script去攔截Enter指令在轉派到按鈕的方式,對於表單輸入有一定的幫助。

直接丟code (C#)

this.TextBox1.Attributes.Add("onkeypress", "if( event.keyCode == 13 ) {" + this.ClientScript.GetPostBackEventReference(this.Button1, "") + "}");
this.TextBox2.Attributes.Add("onkeypress", "if( event.keyCode == 13 ) {" + this.ClientScript.GetPostBackEventReference(this.Button2 , "") + "}"); 

VB.NET

Me.TextBox1.Attributes.Add("onkeypress", "if( event.keyCode == 13 ) {" & Me.ClientScript.GetPostBackEventReference(Me.Button1, "") & "}")
Me.TextBox2.Attributes.Add("onkeypress", "if( event.keyCode == 13 ) {" & Me.ClientScript.GetPostBackEventReference(Me.Button2, "") & "}") 

回應討論