有人知道如何防止HTML复选框在点击时获得焦点吗?我仍然希望它改变状态,只是没有得到关注.
最佳答案
您可以通过在mousedown处理程序中使用preventDefault()来阻止焦点:
原文链接:https://www.f2er.com/html/425898.html$('input[type=checkBox]').mousedown(function (event) {
// Toggle checkstate logic
event.preventDefault(); // this would stop mousedown from continuing and would not focus
});
在纯JavaScript中:
checkBox.onmousedown = function (event) {
// Toggle checkstate logic
event.preventDefault(); // this would stop mousedown from continuing and would not focus
}