本文介绍了chrome中的.blur和.onblur的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新后不起作用--- http://jsfiddle.net/xvepL/4/驾驶我有点疯了! Chrome浏览器不使用.blur仅与.onblur一起使用,但是其他浏览器使用.blur是否可以解决此问题?这两种方法在选择列表上也行不通吗?

updated not working --- http://jsfiddle.net/xvepL/4/ driving me a bit nuts! Chrome doesnt use .blur only works with .onblur but other browsers use .blur is there a way around this? It also both ways does not work on select lists?

没有摆弄浏览器特定的内容

NO fiddle as its browser specific

/* Big Search Box Leave */
    $(".searchbox").onblur(function() {
    var searchbox = this,
        searchbox_val = $.trim( this.value );
    if (searchbox_val.length > 0) {
        $(searchbox).addClass("blur");
        return true;
    } else {
        $(searchbox).removeClass("blur");
        return false;
    }
  });

推荐答案

$(".searchbox").onblur不正确. .onblur()不是jQuery函数.另一方面, .blur() 是.

$(".searchbox").onblur is incorrect. .onblur() is not a jQuery function. On the other hand, .blur() is.

$(".searchbox").blur(function () {
    var searchbox = this,
        searchbox_val = $.trim(this.value);
    if (searchbox_val.length > 0) {
        $(searchbox).addClass("blur");
        return true;
    } else {
        $(searchbox).removeClass("blur");
        return false;
    }
});

DEMO: http://jsfiddle.net/xvepL/2/(在Chrome中可以正常运行)

DEMO: http://jsfiddle.net/xvepL/2/ (Works fine in Chrome)

注意:如果要处理DOM元素而不是 jQuery对象,则.onblur是属性的名称.

Note: .onblur is the name of the property if you were dealing with DOM elements and not jQuery objects.

document.getElementsByClassName('searchbox').onblur = function(){
};

这篇关于chrome中的.blur和.onblur的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 22:41