Onclick event to remove default value in a text input field

前端 未结 9 1275
傲寒
傲寒 2021-02-02 14:57

I have an input field:


How would I get it to remove the pre-defined text (Enter Your Name

9条回答
  •  一整个雨季
    2021-02-02 15:08

    This should do it:

    HTML

    
    

    JavaScript

    function blankDefault(_text, _this) {
        if(_text == _this.value)
            _this.value = '';
    }
    

    There are better/less obtrusive ways though, but this will get the job done.

提交回复
热议问题