Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我可以成功地阻止所有键被按下:
$this.keydown(false);
如何禁用除退格键之外的所有键?
检查keyCode事件参数的:
keyCode
$this.keydown(function(e) { if(e.keyCode !== 8) { e.preventDefault(); } });
这是一个演示。
使用回调,检查按下键的键码,如果是退格键则允许,否则阻止。