頁面上兩個TextBox輸入完按Enter觸發不同的按紐
- 2008-11-14
- 23880
- 0
有時後會很習慣在文字方塊輸入完畢後就按ENTER去執行或是去確定,這篇是利用Java script去攔截Enter指令在轉派到按鈕的方式,對於表單輸入有一定的幫助。
K8s新手村一日逃脫術 [2025-07-19]開課 共7H
Roslyn 魔法工坊:打造你的 Source Generator [2025-08-02]開課 共7H
當 Vibe Coding 遇上 AI Agent 開發 [2025-07-12]開課 共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, "") & "}")
回應討論