繁体   English   中英

如何在 onMouseDown 事件后获得 focus() 工作?

[英]How to get focus() works after onMouseDown event?

在 MouseDown 事件之后,焦点必须重定向到另一个元素,但它会保留在当前元素中。 如何让它工作?

 function setFocus() { alert('MouseDown'); document.getElementById("but").focus(); }
 <button type="button" onmousedown="setFocus()">Press</button> <button id="but" type="button">Test</button>

它是否在等待 MouseUp 事件? 那怎么清除呢? 谢谢!

尝试使用preventDefault() 它阻止了默认的 onmousedown 事件

 function setFocus(e) { alert('MouseDown'); e.preventDefault() document.getElementById("but").focus(); }
 <button type="button" onmousedown="setFocus(event)">Press</button> <button id="but" type="button">Test</button>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM