$('input').keypress(function( e ) { if(e.which === 32) return false;});.$('input').keypress(function( e ) { if(!/[0-9a-zA-Z-]/.test(String.fromCharCode(e.which))) return false;}); 这篇关于如何防止在输入时使用空格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!