0

I wrote some code which is activated when user clicks on input box. I used jQuery("#mydiv").focus();, however, I ran into another problem. Once this is triggered, even if user lost focus from the input box the script runs and requires information wich results in another script breaking (i tried .keyup() and .click() everything had the same result). I want the script run only when the input box has focus, if user clicks off, the script should be inactive. Is it possible to do?

4

2 回答 2

1

您需要使用 .blur 事件来撤消您在焦点事件中所做的任何更改。

因此,如果您(例如)在焦点上将框的背景颜色从白色更改为蓝色,则在模糊事件中您将背景设置回白色。

于 2013-09-17T14:53:32.767 回答
0

在没有看到代码的情况下,我只能根据您的描述提出建议。

尝试类似的东西

$("mydiv").blur(function(){
   alert("Lost its focus.");
});

此外,如果 mydiv 是一个 div,那么请确保这是您想要的,可能是您想使用输入控件进行焦点/模糊。

于 2013-09-17T14:57:24.360 回答