首先代碼:JavaScript值比較是不合邏輯
function focusAction(thefield, autofill) {
if (thefield.value == thefield.defaultValue && (thefield.style.color == 'rgb(153, 153, 153)' || thefield.style.color == '#999999')) {
thefield.style.color = "#000000";
if (autofill == "")
thefield.value = '';
}
}
function blurAction(thefield, autofill) {
//var content = thefield.value;
if (thefield.value == '' || thefield.value == null) {
thefield.value = thefield.defaultValue;
if (autofill == "")
thefield.style.color = "#999999";
} else {
//thefield.style.color="green";
}
}
因此,這裏的交易:如果我把如果(thefield.value == 「」 || thefield.value == NULL)它的工作原理,但你必須有一個空間。如果該框爲空,則不起作用。這隻影響textareas。它適用於空白文本框。
我真的很困惑,任何人有任何想法,爲什麼一個空間的作品,但空的「」或「'或null不?
像往常一樣 - 它不是與JavaScript的問題 - 這是你的代碼有問題。可能是外部部分張貼在問題 –
你應該使用jsfiddle.net來顯示一個例子,你也許想嘗試'.text'而不是value。 – vol7ron
這是因爲您的TEXTAREA元素可能包含一些空白字符。我推薦這樣做:'if(thefield.value.trim()==='')'(請注意'trim()'在IE8中沒有實現,所以你必須手工處理。) –