我有一些像这样的代码来接管空格键的功能:
$(document).keypress(function (e) {
e.preventDefault();
if (e.which == 32) {
// func
}
});
不幸的是,这破坏了所有密钥的默认设置。
This:
$(document).keypress(function (e) {
if (e.which == 32) {
e.preventDefault();
// func
}
});
不幸的是没有效果。
我怎样才能让它防止默认只有空格键?
Thanks.
尝试这个:
//e= e || window.event); you may need this statement to make sure IE doesn't keep the orginal event in motion
var code;
if (e.keyCode) {
code = e.keyCode;
} else if (e.which) {
code = e.which;
}
if (code == 32) {
if (e.stopPropagation) {
e.stopPropagation();
e.preventDefault();
}
return false;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)