gpt4 book ai didi

javascript - 如果按下 Ctrl + F,则禁用表单查找浏览器

转载 作者:行者123 更新时间:2023-11-30 11:40:43 27 4
gpt4 key购买 nike

如果按下 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();
})

图片:

enter image description here

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/

关于javascript - 如果按下 Ctrl + F,则禁用表单查找浏览器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42789427/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com