jQuery 1.4.2:.is(“:focus")给出语法错误 [英] jQuery 1.4.2: .is(":focus") gives syntax error

查看:244
本文介绍了jQuery 1.4.2:.is(“:focus")给出语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设有一个具有单个输入的文档.我想做的就是这样简单:

Assume there is a document with a single input. What I'm trying to do is as simple as this:

$("input").focus().is(":focus");

我希望上面的代码返回true.相反,firebug会记录错误:

I would expect the above code to return true. Instead, firebug logs an error:

Syntax error, unrecognized expression: Syntax error, unrecognized expression: focus

我在这里想念什么?我以为is()所使用的语法与$()相同,还是我无法做到这一点?

What am I missing here? I assumed that the syntax used with is() is identical to $(), or I can't do that?

如果这无法解决,您将如何建议检查重点关注的输入呢?

How would you recommend to check for a focused input if this is unfixable instead?

从jquery 1.6开始,:focus选择器是jquery核心的一部分: http://api.jquery.com/focus-selector/
如果需要,只需升级即可.

As of jquery 1.6, the :focus selector is part of jquery core: http://api.jquery.com/focus-selector/
If you need it, just upgrade.

推荐答案

$("input").focus()应该足够.由于:focus不是选择器.

$("input").focus() should suffice. As :focus is not a selector.

  $("input").focus(function () {
         //do something
    });

$("input:focus").runFunc();我想可能有效. Cletus 总结了这个问题好吧,我认为,值得一看.

$("input:focus").runFunc(); I suppose that might work. Cletus has summed up this problem well I think, its worth a look.

这篇关于jQuery 1.4.2:.is(“:focus")给出语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆