對於文本框的水印文本,我有一個煩人的問題。如果輸入文本然後刪除文本框,則不會將其驗證爲空
我想要的是,如果用戶點擊即可文本框,並有在文本框中沒有文本比默認的文本應該出現(如搜索...)
我有這個功能檢查:
document.getElementById("searchtextbox").onblur = function() {
if (document.getElementById("searchtextbox").value == "") {
document.getElementById("searchtextbox").setAttribute("value", "Search...");
}
它工作的很好,如果我只需點擊裏面並點擊。問題出現在我點擊裏面時,輸入文本並刪除它,然後單擊外部。我試着用Length == 0,value == null,value.trim()==「」,!value.match(/.+/)來做,並且它們都不返回true。
if條件中使用document.getElementById(「searchtextbox」)。value =「search」; – Max 2011-06-07 10:17:28