頁面上兩個TextBox輸入完按Enter觸發不同的按紐
- 2008-11-14
- 23181
- 0
有時後會很習慣在文字方塊輸入完畢後就按ENTER去執行或是去確定,這篇是利用Java script去攔截Enter指令在轉派到按鈕的方式,對於表單輸入有一定的幫助。
精準解析 Entity Framework Core 基礎篇 [2025-03-09]開課 共5H
現代桌面應用程式,玩轉WPF [2025-03-15]開課 共21H
精準解析 Entity Framework Core 進階篇 [2025-03-16]開課 共5H
直接丟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, "") & "}")
回應討論