问题描述
我不明白为什么jQuery模糊处理程序在最简单的情况下不起作用。我实际上创建一个div 100px×100px并在其上设置模糊事件,但它没有触发( ):
I don't understand why the jQuery blur handler isn't working in the most simple case. I'm literally creating a div 100px by 100px and setting a blur event on it, but it's not firing (JSFiddle):
<div id="test">this is a test</div>
$(document).ready(function() {
$('#test').bind('blur', function() {
alert('blur event!');
});
});
我对模糊的理解是错误的吗?我希望当我点击不是div的任何地方时会触发模糊事件...对吗?
Is my understanding of blur wrong? I expect the blur event to fire when I click anywhere that is not the div...right?
根据jQuery的文档:
According to jQuery's documentation:
我在Mac上的最新Chrome和Firefox上试过它。
I've tried it on the latest Chrome and Firefox on Mac.
推荐答案
来自:
blur
blur
jQuery docs状态浏览器将事件扩展到其他元素,我猜这意味着模糊和焦点是更通用的别名提到给元素一个 tabindex
会允许这个,并且似乎在。 (虽然有一个相当丑陋的轮廓。)
This SO question mentions that giving an element a tabindex
would allow that, and seems to work for me in Chrome after modifying your jsFiddle. (Albeit with a fairly ugly outline.)
这篇关于jQuery模糊处理程序不工作div元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!