Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google chrome jquery.live';焦点';事件未在google chrome上触发_Google Chrome_Jquery_Browser Support - Fatal编程技术网

Google chrome jquery.live';焦点';事件未在google chrome上触发

Google chrome jquery.live';焦点';事件未在google chrome上触发,google-chrome,jquery,browser-support,Google Chrome,Jquery,Browser Support,我想知道这是chrome或jQuery中的一个bug,还是我误解了.live函数的用法 $('.input_form input[type="radio"]').live({ 'change':function(){ console.log("this is a radio button"); } }); 当我在所有主要浏览器中单击类为“input_form”的单选按钮时,上述代码将输出发送到控制台窗口 但是,以下代码: $('.input_form input

我想知道这是chrome或jQuery中的一个bug,还是我误解了.live函数的用法

$('.input_form input[type="radio"]').live({
    'change':function(){
        console.log("this is a radio button");
    }
});
当我在所有主要浏览器中单击类为“input_form”的单选按钮时,上述代码将输出发送到控制台窗口

但是,以下代码:

$('.input_form input[type="radio"]').live({
    'focus':function(){
        console.log("this is a radio button");
    }
});
将输出发送到除google chrome(10)之外的所有浏览器的控制台窗口

唯一的区别是将“更改”更改为“焦点”作为事件触发器


有人能解释一下吗?

如果使用jQuery 1.7+,您可能应该:

$(document).on({
    change: function(){
        console.log("this is a radio button on change");
    },
    focus: function() {
        console.log("this is a radio button on focus");
    }
}, '.input_form input[type="radio"]');
如果仍然使用live,并且不需要地图,请执行以下操作:

$('.input_form input[type="radio"]').live('focus', function(){
    console.log("this is a radio button");
});
或使用地图:

$('.input_form input[type="radio"]').live({
    focus: function(){
        console.log("this is a radio button");
    }
});
在webkit中,只有在使用tab时,才不会自动单击单选按钮。 但是,您可以将焦点设置为元素,尽管我无法理解您为什么要这样做,但这是可能的:

$(document).on({
    click: function(){
        console.log("this is a radio button on click");
        $(this).focus();
    },
    focus: function() {
        console.log("this is a radio button on focus");
    }
}, '.input_form input[type="radio"]');

我不确定,但我认为你必须使用
聚焦
而不是
聚焦

$('.input_form input[type="radio"]').live({
    'focusin': function(){
        console.log("this is a radio button");
    }
});
至少在一段时间以前,
focusin
是处理
live
focus
的标准化事件

blur
称为
focus out


注:

当某个元素或其中的任何元素获得焦点时,focusin事件被发送到该元素。这与焦点事件不同,因为它支持在父元素上检测焦点事件(换句话说,它支持事件冒泡)


检查这个问题[1],它表明chrome和safari中的单选按钮不会触发焦点事件


[1]

谢谢您的回答,但更改为focusin对ChromeUpgraded至1.7没有任何影响,它尝试了所有三种解决方案,但仍然无法在chrome中触发“focus”。在您的第一个解决方案中,“this is radio change”会写入控制台,而不是chrome中的“this is radio focus”,在firefox中,这两句话会同时记录time@KevinBradshaw-更新了我的答案,但我相信米尔科更快。接受了米尔科的答案,并对你的答案投了更高的票,因为你的答案内容丰富