开发者

How can I change the Forecolor of the Textbox on the OnClick?

I have 2 textboxes which has default values in forecolor:#999999. If I click on the textbox, the default value should clear and the forecolor should change to black. I mean, like watermarking. But I am not using any Ajax开发者_如何转开发. need help...please...


You should use the onfocus and onblur events, rather than relying on click events. This way, it will work for keyboard users tabbing through the document.

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";
    }
}

See it in action here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜