Div onblur event called when clicking checkbox inside div

一曲冷凌霜 提交于 2019-12-06 17:01:30

On modern browsers the onblur event doesn't fires with div elements, a crossbrowser approach that can also deal with the issues of IE could be to use event delegation, binding a click event handler to the document, and hide the popup when the clicked element is not a checkbox or the lookupButton, for example:

document.onclick = function (e) { 
  e = e || window.event; 
  var element = e.target || e.srcElement; 

  if (element.tagName != "INPUT" && element.type != "checkbox" &&
      element.className != "lookupButton") { 
    hidePopup(); 
  } 
}; 

Check the above example with the rest of your code here.

Try going about it the other way. Use a three-layered approach where the bottom layer is the normal page, the top layer is your popup div, and the middle layer is a transparent, full-screen catch-all div that has an onfocus event that closes your popup (rather than using onblur).

If you provide some code, it'll be easier to help with your approach.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!