jQuery的重点/重点 [英] jquery focus in / out

查看:95
本文介绍了jQuery的重点/重点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为输入焦点上的输入添加活动"类,并在焦点关闭时删除该类.

I would like is to add class "active" to input on input focus, and when focus off, remove that class.

谢谢

推荐答案

一旦包含了jquery lib,这是非常标准的

once you've included the jquery lib, it's pretty standard

$('input').focus( function() {
  $(this).addClass('active');
});

$('input').blur( function() {
  $(this).removeClass('active');
});

聚焦和模糊比聚焦和聚焦更适合输入聚焦.对子对象进行focusin和focusout气泡事件,并且在大多数情况下,这在这里是不必要的.

focus and blur are more appropriate than focusin and focusout for just input focusing. focusin and focusout bubble events to children objects and for the most part, that's (likely) unnecessary here.

相当标准的东西.看看jquery文档了解更多.如果只希望将其用于特定的输入字段,也可以修改选择器(输入"部分).

pretty standard stuff. take a look at the jquery docs for more. also maybe modify the selector (the 'input' part) if you only want it for particular input fields.

选择器示例:

$('input#my_id_is_bob') $('input.my_class_is_activatable')

$('input#my_id_is_bob') for $('input.my_class_is_activatable') for

这篇关于jQuery的重点/重点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆