你会想要的.blur();功能每当一个元素具有“焦点”,并在用户离开“强调”项目,“模糊”被调用,将事件发送回的元素。一个榜样。
if(focusedElement == ""){
//if our focused element is empty
$('#text2display').live('blur', function(){
//when the target loses focus, we invoke blur, the next line focuses again.
//it's also a best practice to do something like fading in the border,
$("#text2display").focus();
});
}
另外,如果我可以建议,让用户知道他们的焦点已经回到那个元素是一个好主意,最好的办法是做一些事情,比如添加一个'红色'边框,然后淡出边框。一种方法如下 - >
if(focusedElement == ""){
//if our focused element is empty
$('#text2display').live('blur', function(){
//when the target loses focus, we invoke blur, the next line focuses again.
//it's also a best practice to do something like fading in the border,
$("#text2display").focus(function(){
$(this).animate({
//when the element has been re-focused, we'll give it a red border briefly.
borderColor: '#ff0000';
}, function(){
//once the animation completes, fade the border out
$(this).animate({ borderColor: 'transparent' }, 2000);
}
);
});
});
}
而且,因为我们不希望调整的问题,我们需要一些CSS添加到我们的投入
input{
border:1px solid transparent;
}
这应该为你工作。
这是什么浏览器运行?它是在移动设备上还是在桌面上? – 2012-03-02 11:38:09