使用jQuery测试输入是否具有焦点

本文翻译自:Using jQuery to test if an input has focus

On the front page of a site I am building, several <div> s use the CSS :hover pseudo-class to add a border when the mouse is over them. 在我正在构建的站点的首页上,几个<div>使用CSS :hover伪类在:hover时添加边框。 One of the <div> s contains a <form> which, using jQuery, will keep the border if an input within it has focus. 其中一个<div>包含一个<form> ,使用jQuery,如果其中的输入具有焦点,它将保持边界。 This works perfectly except that IE6 does not support :hover on any elements other than <a> s. 这完全有效,除了IE6不支持:hover在除<a>的任何元素上。 So, for this browser only we are using jQuery to mimic CSS :hover using the $(#element).hover() method. 所以,对于这个浏览器,我们只使用jQuery来模仿CSS :hover使用$(#element).hover()方法:hover The only problem is, now that jQuery handles both the form focus() and hover() , when an input has focus then the user moves the mouse in and out, the border goes away. 唯一的问题是,现在jQuery处理表单focus() hover() ,当输入具有焦点然后用户移入和移出鼠标时,边框消失。

I was thinking we could use some kind of conditional to stop this behavior. 我以为我们可以使用某种条件来阻止这种行为。 For instance, if we tested on mouse out if any of the inputs had focus, we could stop the border from going away. 例如,如果我们测试鼠标输出是否有任何输入有焦点,我们可以阻

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值