我的代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script src="js/jquery.js"></script>
<script>
$(function(){
$("input").blur(function(){$(this).focus();});});</script>
</head>
<body>
<input type="text" >
</body>
</html>
它没有将输入集中在模糊事件上。为什么?建议解决方案?
答案 0 :(得分:3)
试试这段代码:)
<script type="text/javascript">
$(function(){
$("input").blur(function(){
setTimeout(function(){ $("input").focus(); }, 20);
});
$("input").focusout(function(){
setTimeout(function(){ $("input").focus(); }, 20);
});
});
</script>
答案 1 :(得分:0)
尝试这样的事情
<script>
$(function(){
$("input").blur(function(){
setTimeout(function() {$(this).focus();}, 20);
});
});
</script>
答案 2 :(得分:0)
尝试这个,它对我来说非常有用:
<script>
$(function(){
$("input").blur(function(){
(function(that) {
setTimeout(function(){
var oldTabIndex = that.attr('tabindex');
that.attr("tabindex", 1);
$(window).focus();
if (!that.is(':focus')) {
that.focus();
}
that.attr('tabindex', oldTabIndex);
}, 50);
})($(this));
});
});
</script>