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

标签 javascript jquery html css browser

如果按下 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/

相关文章:

jquery - 更改日期颜色

php - 制作响应式页面时 jquery.min 文件冲突

javascript - Html5 音频标签在 iOS7 设备上不起作用

javascript - ReactJS 文本输入

javascript - 快速 Javascript 考虑了 document.getElementByClassName 来修复错误

javascript - 如何使用计时器协调 2 个函数 -> javascript

javascript - 制作位置 :absolute div relative after toggleFade()

jquery - 如何使用 jQuery 隐藏不包含数据类特定值的所有元素?

javascript - 如何让我的提交按钮启动 JQ 功能?

php - 通过 GET 将 PHP 数组传递给 Javascript