文本框失去焦点时的jQuery函数 [英] Jquery function when a textbox loses focus
问题描述
我有一个文本框,当文本框失去焦点时,我想运行一些jquery,因此在用户单击文本框之后.
I have textbox that I want to run some jquery when the textbox loses focus, so after the user clicks out of the text box.
我试图做到这一点
$("#textbox").focusout(function () {
alert("hello");
});
但是我收到一个错误消息,说对象不支持该属性或方法.
but I get an error saying Object doesn't support this property or method.
那我该怎么办?
推荐答案
focusout
在v1.4中.三个想法:
focusout
was added in v1.4. Three thoughts:
- 您是否可以使用早期版本的jQuery?
- 您的字段是否真的具有ID
textbox
? - 您是否还在使用Prototype或MooTools(或可能取代
$
的其他任何工具)?如果是这样,请使用jQuery的noConflict
模式,并使用jQuery
而不是$
.
- Could you be using an earlier version of jQuery?
- Does your field really have the id
textbox
? - Are you also using Prototype or MooTools (or anything else that might be taking over
$
)? If so, use jQuery'snoConflict
mode and usejQuery
instead of$
.
除此之外,它应该(确实)起作用.
Other than that, it should (does) work.
这是一个示例(像您一样使用警报): http://jsfiddle.net/QzmZp/1 /
另一个未使用警报(因为IE7崩溃了): http://jsfiddle.net/QzmZp /2/
之前有人问过浏览器版本,我已经在Chrome 5,IE6,IE7和FF3.6上尝试过以上版本;一切都很好.
Here's an example (using an alert as you did): http://jsfiddle.net/QzmZp/1/
and another not using an alert (because that freaked IE7 out): http://jsfiddle.net/QzmZp/2/
Someone earlier asked about browser versions, I've tried the above with Chrome 5, IE6, IE7, and FF3.6; all fine.
我同时做了input
和textarea
,因为我不确定您使用的是哪个.
I did both an input
and a textarea
because I wasn't sure which you were using.
这篇关于文本框失去焦点时的jQuery函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!