admin管理员组文章数量:1333442
I wonder how to set the focus to an input field on the mouseover event.
I wonder how to onload input field or onfocus field for typing when onmouseover to it so it easily ready to type when cursor touching or onmouseover cursor to input field of search box.
I wonder how to set the focus to an input field on the mouseover event.
I wonder how to onload input field or onfocus field for typing when onmouseover to it so it easily ready to type when cursor touching or onmouseover cursor to input field of search box.
Share edited Oct 6, 2016 at 17:32 Enamul Hassan 5,44523 gold badges43 silver badges58 bronze badges asked Oct 6, 2016 at 16:25 Keta SambungbyrKeta Sambungbyr 311 gold badge1 silver badge2 bronze badges 03 Answers
Reset to default 4You can use the focus()
method to focus an HTML element. Here's an example of its usage:
var inputField = document.getElementById('idOfYourInputField');
inputField.addEventListener('mouseover', function() {
inputField.focus();
});
Using jQuery:
$('.input-element').mouseover(function() {
$(this).focus();
})
Or if you want to control the focus and blur events
$('.input-element')
.mouseenter(function() {
$(this).focus();
})
.mouseleave(function() {
$(this).blur();
});
Not sure what you are expecting here but if you want something like at certain position on page if user moves mouse you want the textbox to get Focus you can do something like:
<div id='d1'>
<input type='text' id='txt' value='Search'/>
</div>
and with Jquery:
$().ready(function(){
$('#d1').mouseover(function(){
$(this).children().closest('Input[type=text]').focus();
});
});
本文标签: javascriptHow to set focus to an input element (searchbox) on mouseoverStack Overflow
版权声明:本文标题:javascript - How to set focus to an input element (searchbox) on mouseover? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742292056a2447988.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论