听起来像你总是希望你的输入之一是专注,公平的。我会这样做的方式是绑定每个输入事件,以便发生时它将转到下一个元素。
这里的标记:
<body>
<form method="POST" action=".">
<input type="text" name="username" />
<input type="password" name="password" />
<input type="submit" name="submit" />
</form>
</body>
而这里的jQuery的:
$(document).ready(function() {
// what are the named fields the user may focus on?
var allowed = ['username', 'password', 'submit'];
$.each(allowed, function(i, val) {
var next = (i + 1) % allowed.length;
$('input[name='+val+']').bind('blur', function(){
$('input[name='+allowed[next]+']').focus();
});
});
$('input[name='+allowed[0]+']').focus();
});
Eugh。请不要尝试这样做。如果用户想把焦点放在别的地方,让他们把它放在别的地方。 – Quentin 2010-06-10 14:14:34
也许这种非常恼人的焦点行为是你被要求做的事情,所以你没有什么权力去做别的事情,但是想一想:是否真的值得麻烦?它有用吗?甚至有必要? – Humberto 2010-06-10 14:23:32
@Misha:欢迎编程一个Web应用程序! – 2010-06-13 17:15:30