3body

JQuery输入框获取/失去焦点行为

//搜索框获取焦点清除内容
$(function() {
    $("input").focus(function() { //获取焦点,清空默认内容
        $(this).css(\'color\', \'black\').addClass(\'focus\');
        if ($(this).val() == this.defaultValue) {
            $(this).val(\'\');
        }
    }).blur(function() { //失去焦点,若没有内容,则恢复默认内容;有内容则不变
        $(this).removeClass(\'focus\');
        if ($(this).val() == \'\') {
            $(this).val(this.defaultValue).css(\'color\', \'#aaa\');
        }
    });
});

注:.focus只是输入框的css效果,可以忽略

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2021-07-02
  • 2022-01-09
  • 2021-12-19
  • 2021-12-19
  • 2022-12-23
  • 2021-12-19
  • 2021-11-30
猜你喜欢
  • 2021-12-19
  • 2021-12-19
  • 2022-12-23
  • 2022-12-23
  • 2021-12-19
  • 2021-12-19
  • 2022-12-23
相关资源
相似解决方案