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