刪除多個文本域文字我有這樣的代碼至極去除textarea的文本只在第一次點擊。它只能確定,直到我寫的第二textarea標籤至極爲:<textarea id="textarea2" onfocus="checkOnFocus(this);" onblur="resetInitialText(this);">Your second message</textarea>
只在第一次點擊
代碼:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript">
var flag = false;
function setInitialText() {
var textarea = document.getElementById('textarea');
if (textarea.value == "") {
textarea.value = text;
}
}
function checkOnFocus(textarea) {
if (!flag) textarea.value = "";
flag = true;
}
function resetInitialText(textarea) {
if (textarea.value == "") {
textarea.value = text;
flag = false;
}
}
</script>
</head>
<body onload="setInitialText();">
<textarea id="textarea" onfocus="checkOnFocus(this);" onblur="resetInitialText(this);">Your first message</textarea>
<textarea id="textarea2" onfocus="checkOnFocus(this);" onblur="resetInitialText(this);">Your second message</textarea>
</body>
</html>
縮進你的代碼會傷害嗎? – PeeHaa
你在控制檯中有任何錯誤嗎? – wakooka
您對兩個textareas使用相同的全局「標誌」。爲什麼要避免全球國家的完美例子。 – Yoshi