简体   繁体   English

如何仅在输入字段外部检测Ctrl + End键?

[英]How to detect key Ctrl+End only outside input field?

How to detect key Ctrl+End only outside input field ? 如何仅在输入字段外部检测Ctrl+End键?

When i press Ctrl+End it's will be alert foo 当我按Ctrl+End时会提示foo

And when i click in input field and press Ctrl+End I don't want to alert , How can i do ? 当我单击输入字段并按Ctrl+End我不想提醒我,该怎么办?

http://jsfiddle.net/C7PZB/39/ http://jsfiddle.net/C7PZB/39/

$(function() {
    $(document).on('keyup keydown keypress', function(event) {
        console.log(event);
        if(event.keyCode== 35 && event.ctrlKey) {
            alert('foo');
        }
    });
});

Use .not("input") 使用.not("input")

 $(function() { $(document).not("input").on('keyup keydown keypress', function(event) { console.log(event); if(event.keyCode== 35 && event.ctrlKey) { alert('foo'); } }); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input type="text"> 

But remember there is no End key on MAC :P 但是请记住, MAC :P上没有End

You can use .is(':input') to check the element is input or not like following. 您可以使用.is(':input')来检查元素是否输入,如下所示。 Hope this will help you. 希望这会帮助你。

 $(document).on('keyup', function(event) { if(!$(event.target).is(':input')){ if(event.keyCode== 35 && event.ctrlKey) { alert('foo'); } } }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input type="text"/> 

FIDDLE 小提琴

如何将“ctrl+end”键发送到<textarea>&lt;i&gt;element so the cursor lands after last character&lt;/div&gt;&lt;/i&gt;&lt;b&gt;元素,所以 cursor 在最后一个字符之后着陆&lt;/div&gt;&lt;/b&gt;</textarea><div id="text_translate"><p> (发送:即模拟用户通常会键入这些键)</p><p> 我知道这个方法 element.value = element.value,但我认为对于其中包含大量数据的文本区域(如 wiki 等)可能会很慢。</p></div> - How to send the 'ctrl+end' key to <textarea> element so the cursor lands after last character

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将“ctrl+end”键发送到<textarea>&lt;i&gt;element so the cursor lands after last character&lt;/div&gt;&lt;/i&gt;&lt;b&gt;元素,所以 cursor 在最后一个字符之后着陆&lt;/div&gt;&lt;/b&gt;</textarea><div id="text_translate"><p> (发送:即模拟用户通常会键入这些键)</p><p> 我知道这个方法 element.value = element.value,但我认为对于其中包含大量数据的文本区域(如 wiki 等)可能会很慢。</p></div> - How to send the 'ctrl+end' key to <textarea> element so the cursor lands after last character 检测输入文本字段之外的模糊 - Detect on blur outside of input text field 如何在提交表单之前检测输入字段上的 ENTER 键按下? - How to detect ENTER key press on an input field before the form is submitted? 释放CTRL-F时如何检测CTRL键的“ key up”事件? - How to detect the “key up” event of the CTRL key when releasing CTRL-F? 检测文本输入字段中的 Enter 键 - Detect the Enter key in a text input field 检测输入字段上的回车键 - Detect enter key press on input field 单击输入字段后如何检测鼠标在表单外单击 - How to detect mouse click outside the form right after clicking input field SendKeys仅在文本字段中输入结束 - SendKeys is only putting end of input in text field 如何使用正则表达式检测CTRL + C和CTRL + V键? - how to detect CTRL+C and CTRL+V key pressing using regular expression? 如何在文本区域和输入之外检测选择 - How to detect selection outside textarea and input
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM