草庐IT

LostFocus

全部标签

javascript - 是否可以使用 JS 或 jQuery 为 DIV 编写 onFocus/lostFocus 处理程序?

我有一个div,当用户单击div时,应该调用一个函数。当用户点击其他东西(除了这个div之外的任何东西)时,应该调用另一个函数。所以基本上我需要调用与此DIV关联的onFocus()和lostFocus()函数。它在JavaScript甚至jQuery中可用吗?谢谢。 最佳答案 div需要添加tabindex属性:$("#mydiv").focusin(function(){$("#mydiv").css("background","red");});$("#mydiv").focusout(function(){$("#mydiv

c# - 为什么会在不同时间调用 LostFocus 事件?

引用thisMSDNpage(或有关此事的任何相关页面),它指出:Whenyouchangethefocusbyusingthekeyboard,focuseventsoccurinthefollowingorder:EnterGotFocusLeaveValidatingValidatedLostFocus但是,当您使用鼠标引发事件时,顺序会发生变化!WhenyouchangethefocusbyusingthemouseorbycallingtheFocusmethod,focuseventsoccurinthefollowingorder:EnterGotFocusLostFoc