我正在做一个项目,其中包括一个智能搜索引擎。
我想要写一种让客户端在智能搜索中写入的方法,即使它不是焦点。F.e.在浏览站点时,客户端按下一个键,focus跳转到智能搜索。
这个简单的代码运行得很好:
$(document).ready(function()
{
$("*").keydown( function()
{
$("input.ss-24#b").focus();
});
});但是,正如你所看到的,不聚焦其他输入,这不是我想要的方式。我尝试过几种“可能的解决方案”,比如:not(),甚至.not()方法,比如:
$(document).ready(function()
{
$("*").not("input").keydown( function()
{
$("input.ss-24#b").focus();
});
});但它仍然是,也不使用“输入”标签名对字段进行对焦。如何强制jQuery 而不是为此事件侦听器选择输入字段?
谢谢,史蒂文。
发布于 2013-10-04 14:32:12
$(document).keydown(function() {
if (!$('input').filter(':focus').length) {
$('#b').focus();
}
});工作小提琴
发布于 2013-10-04 14:31:39
$(document).ready(function () {
$(document).keydown(function (e) {
$("input.ss-24#b").focus();
});
});这行得通吗?
http://jsfiddle.net/Xbbu8/
https://stackoverflow.com/questions/19183675
复制相似问题