How to prevent an element from losing focus?

后端 未结 6 1812
忘掉有多难
忘掉有多难 2020-12-30 01:36

How to keep the Focus on one textbox ? even if you click anywhere in a browser.

$(\"#txtSearch\").focus();
6条回答
  •  甜味超标
    2020-12-30 02:10

    There are other ways of loosing focus than clicking area away from the input i.e. tabbing. If you want to prevent loosing focus use blur event i.e.

    document.getElementById('txtSearch').addEventListener('blur', e => {
      e.target.focus();
    });

提交回复
热议问题