admin管理员组文章数量:1432436
When I click on search icon with mouse it works fine , but when i use tab and focus goes to icon but when i enter "ENTER" keyword it won't work .
` <%-- Mobile Only - Search Icon --%>
<div class="mobile-header-icon" onclick="OnClickSearchIcon();" tabindex="0"
aria-label="Search">
<i class="search" ></i>
</div>`
When I click on search icon with mouse it works fine , but when i use tab and focus goes to icon but when i enter "ENTER" keyword it won't work .
` <%-- Mobile Only - Search Icon --%>
<div class="mobile-header-icon" onclick="OnClickSearchIcon();" tabindex="0"
aria-label="Search">
<i class="search" ></i>
</div>`
Share
Improve this question
asked Mar 31, 2022 at 8:04
tech cooltech cool
631 silver badge4 bronze badges
1 Answer
Reset to default 4Pressing enter
does not fire a click event.
You could add a listener for e.g. keyup event.
Here is a full working example:
function OnClickSearchIcon(){
// do whatever you want instead of this
document.body.innerHTML += "<p>Search!</p>";
}
function onKeyUp(e){
if (e.key === "Enter") OnClickSearchIcon();
}
<div tabindex=0 onkeyup="onKeyUp(event)" onclick="OnClickSearchIcon()" >
<i class="search" >Click, or focus me and press Enter</i>
</div>
本文标签: javascripttabindex is given it is focusing but on enter key enter it won39t workStack Overflow
版权声明:本文标题:javascript - tabindex is given it is focusing but on enter key enter it won't work - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745430403a2658299.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论