在文本框中禁用 space(同时输入 spacebar 并从其他地方复制 whitespace)
Disable space in textbox (both typing spacebar and copy whitespace from other)
防止键入 space 代码如下所示 (Javascript)
function RestrictSpace() {
if (event.keyCode == 32) {
return false;
}
}
但不能防止糊白space
如何解决?
谢谢。
HTML
<input type="text"onchange="myFunction(event)">
JS
function myFunction(event) {
console.log(event.target.value)
event.target.value = event.target.value.replace(/\s/g, "");
}
防止键入 space 代码如下所示 (Javascript)
function RestrictSpace() {
if (event.keyCode == 32) {
return false;
}
}
但不能防止糊白space 如何解决? 谢谢。
HTML
<input type="text"onchange="myFunction(event)">
JS
function myFunction(event) {
console.log(event.target.value)
event.target.value = event.target.value.replace(/\s/g, "");
}