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

查看:30
本文介绍了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天全站免登陆