jquery检测手机软键盘
jQuery插件,用于检测用户是否砸了键盘。 这取决于触发事件的按下键的数量……不错!
可以用来平息办公室里那些疯狂的人!
演示版
(function($){
$.fn.extend({
onKeyboardSmashed : function(callbackFunction,options) {
var defaults = {
//change here for event trigger
threshold: 3
};
var options = $.extend(defaults, options);
return this.each(function() {
var keys_pressed = 0 ;
$(this).keydown(function(event) {
keys_pressed++
if( keys_pressed >options.threshold){
if(typeof callbackFunction == 'function'){
callbackFunction.call(this);
}
}
});
$(this).keyup(function(event) {
keys_pressed--;
});
});
}
});
})(jQuery);
//usage
$(document).onKeyboardSmashed(function(){
$("#status").html('keyboard smashed');
$("#msg").hide();
});
翻译自: https://www.sitepoint.com/jquery-detect-user-smashes-thier-keyboard/
jquery检测手机软键盘