3 回答

TA贡献1813条经验 获得超2个赞
onmousedown之前活跃onblur
div.addEventListener('mousedown', function(event) {
event.preventDefault();
event.stopPropagation();
});

TA贡献1963条经验 获得超6个赞
当 onblur 运行时,它将隐藏 div,因此当要进行单击时,它不会在 div 上触发,因为 div 是不可见的。所以 :
// use the following global variable
var mytimer = null;
function newOnBlur()
{
mytimer = setTimeout(YourCurrentOnBlurFunctionWihoutParentheses,150);
}
// clearTimeout in the first line of your click function
function newOnClick()
{
clearTimeout(mytimer);
// rest of your click event
}

TA贡献1828条经验 获得超3个赞
全局变量看起来有点难看,但这似乎是做到这一点的唯一方法。
对于那些有同样问题的人: setTimeout 在我的例子中有点迂腐。我必须以这种方式设置它,否则永远不会使用超时:
var timer = null;
function timer_function(divname)
{
timer = setTimeout(function(){document.getElementById(divname).style.display='none'}, 200);
}
如果超时被清除,我必须重新聚焦到文本框,否则模糊功能将不再起作用。
感谢您的时间和帮助。:)
添加回答
举报