有一个文本框<input />

该文本框并且绑定了事件:

window.onload=function(){
     document.getElementByIdx_x("abc").onblur = function(){
      alert("失去焦点");
     }
    } 

那么默认情况下点击abc这个文本框之外的元素都会使其触发blur事件

如果在元素上添加如下属性并且值为on就不会让之前获得焦点的任何元素失去焦点:

 <span unselectable="on">No blur</span>

 <span unselectable="">Yes blur</span>

但chrome中不支持此属性

可以通过

样式解决:

style="-moz-user-select:none;" 

 

style="-webkit-user-select:none;"

 但是  ,啊 但是  也只能选不中文本,而不能阻止其失去焦点。

相关文章:

  • 2021-12-19
  • 2021-12-19
  • 2021-12-19
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-02
  • 2021-08-30
猜你喜欢
  • 2022-12-23
  • 2021-11-03
  • 2021-12-19
  • 2022-12-23
  • 2021-05-18
  • 2022-12-23
  • 2021-12-19
相关资源
相似解决方案