我有2个文本框,在forecolor中有默认值:#999999。如果单击文本框,则应清除默认值,并且前景颜色应更改为黑色。我的意思是,像水印一样。但我没有使用任何Ajax。需要帮助......请...
答案 0 :(得分:2)
您应该使用 onfocus 和 onblur 事件,而不是依赖点击事件。这样,它将适用于键盘用户标签文档。
var myInput = document.getElementById("myInput");
myInput.onfocus = function () {
if (this.value == "Default Input Value") {
this.value = "";
this.style.color = "#000";
}
}
myInput.onblur = function () {
if (this.value == "") {
this.value = "Default Input Value";
this.style.color = "#999";
}
}
在行动here中查看。