How to clear text field on focus of text field

前端 未结 9 1939
悲&欢浪女
悲&欢浪女 2020-12-29 12:15

I want to clear the text field when the user clicks on that

9条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-29 13:03

    You can use .

    This way, the field will be cleared when it gains focus. However, if you only want to clear it when user clicks on it (i.e. not when the field gains focus with the keyboard for example), then use onclick instead of onfocus.

    However, as pointed by David Dorward in a comment, this behavior may not be expected by the user. So be careful to set this feature on really specific fields (such as search field).

提交回复
热议问题