jQuery Blur在href之前触发 [英] jQuery Blur Fires Before href
本文介绍了jQuery Blur在href之前触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用Ajax搜索\建议框.我使用jQuery处理文本框失去焦点.但是,当我单击建议列表中的链接时,jQuery会触发模糊事件,并且不会遵循该链接.这是jQuery代码:
I am trying to use an Ajax search\suggest box. I use jQuery to handle the textbox losing focus. However, when I click on a link in the suggestion list jQuery fires the blur event and the link is not followed. Here is the jQuery code:
$(document).ready(function() {
$('#lstxt').click(function() {
this.value = '';
});
$('#lstxt').blur(function() {
this.value = 'Database Search';
document.getElementById('ls').innerHTML='';
document.getElementById('ls').style.border='0px';
});
});
如果在建议列表(id ="ls_table")中单击链接,如何避免不触发.blur?
How do I get it to not fire .blur if a link is being clicked inside the suggestion list (id="ls_table")?
推荐答案
var global_switch = false;
$('#ls_table').hover (
function () { global_switch = true; },
function () { global_switch = false; }
)
$('#lstxt').blur(function() {
if (global_switch) { return; } else { ...});
这只是概念证明.与往常一样,全局变量是错误的.看看jQuery的数据API 可以绕过它.
This is just a proof of concept. As always, global variables are bad. Take a look at jQuery's data API to circumvent it.
干杯
这篇关于jQuery Blur在href之前触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文