How to clear a textbox onfocus?

前端 未结 2 1740
夕颜
夕颜 2020-12-29 23:51

I\'ve tried this but it doesn\'t work:

$(function() {
    $(\'input[type=text]\').focus(function() {
      $(this).val() == \'\';
      });
 });
2条回答
  •  甜味超标
    2020-12-30 00:38

    To set the value, you have to pass the new value as a parameter. This is a funky thing with the .val() jQuery function.

    $(this).val('')
    

    take a look at the jQuery API and search for 'val'

提交回复
热议问题