简体   繁体   English

jQuery .blur()不受影响-为什么?

[英]jQuery .blur() not being affected - why?

I googled this question and couldn't find an answer. 我用谷歌搜索了这个问题,但是找不到答案。

I am trying to have an alert appear when a user unfocuses off of any input on my form. 当用户将焦点移到表单上的任何输入上时,我试图显示警报。 I discovered the blur and focusout function so my code looks like: 我发现了模糊和聚焦功能,因此我的代码如下所示:

$("input").blur(function() {
    alert("Unfocused");
});

This works for my input fields no problem. 这适用于我的输入字段,没有问题。 But for my radio button inputs it doesn't work. 但是对于我的单选按钮输入,它不起作用。 I looked through the docs and google and couldn't figure out why. 我浏览了文档和谷歌,不知道为什么。

$("input:radio").blur(function() {
    alert("Unfocused");
});

Test this code. 测试此代码。

替代文字

Test with text and radio.. 测试文本和广播。

替代文字

THIS DOESN'T WORK IN SAFARI AND CHROME BECAUSE THEY ARE WEBKIT BASED. 因为它们是基于WebKIT的,所以不能在Safari和Chrom中使用。

Just put : before like this: 只要把:以前是这样的:

$(":input").blur(function() {
    alert("Unfocused");
});

The :input filter selector selects all type of inputs. :input过滤器选择器选择所有输入类型。

From Docs: 从文档中:

Description: Selects all input, textarea, select and button elements. 说明:选择所有输入,文本区域,选择和按钮元素。

http://api.jquery.com/input-selector/ http://api.jquery.com/input-selector/


To select radio only, you should use :radio filter selector instead: 要仅选择广播,则应使用:radio过滤器选择器:

$(":radio").blur(function() {
    alert("Unfocused");
});

To get little speed gain, you should prepend keyword input like this: 要获得很少的速度提升,您应该像这样在关键字input

$("input:radio").blur(function() {
    alert("Unfocused");
});

More Info: 更多信息:

http://api.jquery.com/radio-selector/ http://api.jquery.com/radio-selector/


Here are more form selectors: 以下是更多form选择器:

Form Selectors 表单选择器

There are a few selectors for form elements: 表单元素有一些选择器:

* :input Selects all form elements (input, select, textarea, button).
* :text Selects all text fields (type="text").
* :password Selects all password fields (type="password").
* :radio Selects all radio fields (type="radio").
* :checkbox Selects all checkbox fields (type="checkbox").
* :submit Selects all submit buttons (type="submit").
* :image Selects all form images (type="image").
* :reset Selects all reset buttons (type="reset").
* :button Selects all other buttons (type="button").
* :file Selects all <input type="file">. 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM