JQuery 在 keyup 后恢复为原始 CSS
我有以下功能:
function setDropLinkFocus(divID){
$("#" + divID).css("font-weight", "Bold");
}
它会在 keyup 事件和 mouseover 事件上触发。在鼠标悬停时,它执行得很好,但在 keyup 事件上,它执行,但大约一秒钟后恢复到原始 CSS。使用元素检查器,我可以看到 CSS 也被添加,然后快速删除。我尝试使用以下方式处理键盘:
$(this).keyup(function)
和:
$(this).live('keyup',function)
编辑: 我发现了问题。发生这种情况是因为 keyup 事件还调用了 AJAX 自动完成下拉函数(我没有将其添加到 JSFiddle)。因此,这些元素并没有被恢复,而是通过 AJAX 调用进行刷新。我对其进行了更改,这样就不会根据我需要的特定关键代码调用 AJAX 函数。
感谢您的帮助!
I have the following function:
function setDropLinkFocus(divID){
$("#" + divID).css("font-weight", "Bold");
}
which fires on both a keyup event and a mouseover event. On mouseover, it excutes fine, but on a keyup event, it executes, but then reverts back to the original css after about a second. Using the element inspector, I can see that the css is also added, and then quickly removed. I've tried handling the keyup with:
$(this).keyup(function)
and:
$(this).live('keyup',function)
EDIT:
I found the problem. This was happening because the keyup event was also calling an AJAX autocomplete-dropdown function (which I didn't add to JSFiddle). So, the elements weren't being reverted, rather, they were being refreshed from the AJAX call. I changed it so the AJAX function isn't called upon the specific key code that I need.
Thanks for all the help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论