如果按Ctrl + F并聚焦到元素,如何禁用表单查找浏览器
html
<div id='demo'>
<form class="id5-text-find-form" id="id5-text-find-form">
<input class="search" placeholder="Find..." type="text">
<input class="reset" type="reset" value="x">
</form>
</div>
<textarea id="area">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</textarea>
css:
#demo {
display:none;
}
#area {
width:100%;
height:200px;
}
kbd {
border:1px solid grey;
padding:4px;
}
jQuery的:
$(document).keydown(function(e) {
if ( e.ctrlKey && ( e.which === 70 ) ){
$("#demo").show();
}
})
$(".reset").click(function() {
$("#demo").hide();
})
图片 :
Fiddle Demo :
最佳答案
在keydown函数中使用e.preventDefault()
来防止默认行为
使用$(".search").focus();
设置焦点
$(document).keydown(function(e) {
if ( e.ctrlKey && ( e.which === 70 ) ){
$("#demo").show();
e.preventDefault();
$(".search").focus();
}
})
https://jsfiddle.net/ycgdd1gd/2/