How to clear a textbox using javascript

前端 未结 15 2224
失恋的感觉
失恋的感觉 2020-12-05 09:45

I have a


I need a javascript method to clear the value of the textbox when the focus is

15条回答
  •  孤城傲影
    2020-12-05 10:22

    It sounds like you're trying to use a "watermark" (a default value that clears itself when the user focuses on the box). Make sure to check the value before clearing it, otherwise you might remove something they have typed in! Try this:

    
    

    That will ensure it only clears when the value is "A new value".

提交回复
热议问题