Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/86.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
Javascript jQuery 1.10.2未在flash对象上触发的事件_Javascript_Jquery_Flash_Events - Fatal编程技术网

Javascript jQuery 1.10.2未在flash对象上触发的事件

Javascript jQuery 1.10.2未在flash对象上触发的事件,javascript,jquery,flash,events,Javascript,Jquery,Flash,Events,HTML 为什么onfocus有效,而on('focus')无效?jQuery除了转发事件之外还有什么作用吗?试试这个 //This works, so it looks like focus should work an any element with tabindex set $('#div').on('focus', function() { console.log('Div focus event'); }); //This works, so it looks like t

HTML

为什么
onfocus
有效,而
on('focus')
无效?jQuery除了转发事件之外还有什么作用吗?

试试这个

//This works, so it looks like focus should work an any element with tabindex set
$('#div').on('focus', function()
{
    console.log('Div focus event');
});

//This works, so it looks like the browser and Flash support the events
$('#swf').onblur = function()
{
    console.log('SWF onblur');
}

//This does not work
$('#swf').on('focus', function()
{
    console.log('SWF focus event');
});

希望有帮助

Try$('#swf').focus(function(){});on('focus','#swf',function(){})@SubashSelvaraj谢谢,第二个版本适合我。如果你把它放在一个答案中,我会把它标记为正确的。另外,有没有一种方法可以只使用jQuery对象而不是id选择器来实现这一点?e、 g.
$(body).on('focus',$element,…)
@SeanFujiwara不,不是您在那里的方式,根据文档,(可选)第二个参数必须是选择器字符串,而不是已经选择的对象引用。这样,动态事件处理就可以动态地工作。如果将对象传递给它,我认为
.on()
将假定这是可选的第三个参数,
data
。选中此项,函数将接受选择器而不是对象。
//This works, so it looks like focus should work an any element with tabindex set
$('#div').on('focus', function()
{
    console.log('Div focus event');
});

//This works, so it looks like the browser and Flash support the events
$('#swf').onblur = function()
{
    console.log('SWF onblur');
}

//This does not work
$('#swf').on('focus', function()
{
    console.log('SWF focus event');
});
$(body).on('focus', '#swf', function(){});