我有一個登錄表單。我有一個帶有登錄和關閉按鈕的用戶名和密碼文本框。
我想:
- 在用戶名和密碼欄位中顯示“用戶名”的文本。
- 當點擊文本消失。
- 如果單擊并且您專注于其他內容而不輸入任何內容,它將回傳到占位符。
我試過這個:
Private Sub Form_Load()
txt_username.Value = "Username"
txt_password.Value = "Password"
End Sub
Private Sub txt_username_Click()
If txt_username.Value = "Username" Then
txt_username.Value = ""
End If
End Sub
Private Sub txt_username_LostFocus()
If txt_username.Value = "" Then
txt_username.Value = "Username"
End If
End Sub
我唯一的問題是,當進行更改時,IE 鍵入一些內容,然后將其洗掉,在您執行其他操作后,占位符不會回傳。打字破壞了我的代碼。
請幫忙。湯姆
uj5u.com熱心網友回復:
你很接近。嘗試使用“GotFocus”而不是“Click”:
Option Explicit
Private Sub Form_Load()
txt_username.Text = "Username"
txt_password.Text = "Password"
End Sub
Private Sub txt_username_GotFocus()
If Trim(txt_username.Text) = "Username" Then
txt_username.Text = ""
End If
End Sub
Private Sub txt_username_LostFocus()
If Trim(txt_username.Text) = "" Then
txt_username.Text = "Username"
End If
End Sub
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/353167.html
標籤:vba 数据库 验证 ms-access-2016
下一篇:檢查輸入的長度并使用引導程式驗證