0

假设我有一个字段和一个按钮。该按钮提交字段并触发一些将数据返回到同一页面的 AJAX 请求。每次单击按钮时,都会取消选择/模糊该字段。这可以通过使按钮在单击时聚焦文本字段来部分解决。但是,在单击期间,字段会出现短暂的模糊。我设置页面的方式看起来不太好。我想完全防止该字段在整个点击过程中模糊。最简单的方法是什么?谢谢!

代码:

<input type="text" id="f" autofocus/><span id="btn" onclick="document.getElementById('f').focus()"></span>
4

1 回答 1

1

您可以将焦点移到按钮焦点上,而不是处理按钮单击,超时时间非常短:

jQuery:

$('#btn').focus(function (event) {
    setTimeout(function () {
        $('#f').focus();
    }, 5);
});

JavaScript:

document.getElementById('btn').onfocus = function (event) {
    setTimeout(function (event) {
        document.getElementById('f').focus();
    }, 5);
};
于 2013-02-04T17:55:53.357 回答