文本框失去焦点时的jQuery函数 [英] Jquery function when a textbox loses focus

查看:114
本文介绍了文本框失去焦点时的jQuery函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文本框,当文本框失去焦点时,我想运行一些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:

  1. 您是否可以使用早期版本的jQuery?
  2. 您的字段是否真的具有ID textbox?
  3. 您是否还在使用Prototype或MooTools(或可能取代$的其他任何工具)?如果是这样,请使用jQuery的 noConflict 模式,并使用jQuery而不是$.
  1. Could you be using an earlier version of jQuery?
  2. Does your field really have the id textbox?
  3. Are you also using Prototype or MooTools (or anything else that might be taking over $)? If so, use jQuery's noConflict mode and use jQuery 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.

我同时做了inputtextarea,因为我不确定您使用的是哪个.

I did both an input and a textarea because I wasn't sure which you were using.

这篇关于文本框失去焦点时的jQuery函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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