0
我想让数字字符和连字符在keydown上使用。连字符的ascii代码应该是45,但是当我按下它或下划线时,它会显示189。我的页面顶部有charset = utf-8,但字母和数字的ascii字符正确,不是特殊字符。特殊字符也不匹配ascii或utf-8 ..有没有什么办法来检查正在使用什么字符编码或有一个更好的方法来做到这一点?帮助非常感谢试图阻止/允许通过ASCII代码输入某些字符
<script>
//allow alphanumeric and dash
$("#title.mgrid_text").on("keydown",function(e){
console.log(e.which);
if((e.which >= 65 && e.which <= 90) || (e.which >= 97 && e.which <= 122) || e.which == 45 || (e.which >= 48 && e.which <= 57)){
return true;
}
else{
return false;
}
});
</script>