同时键入到一个文本框的网页上删除所有空间文本框、网页、空间

2023-09-11 00:55:49 作者:我十拿九稳就差你一吻

我怎么可能,在飞行中,删除空格进入了一个文本框,而人是打字?

解决方案

  $(函数(){
  VAR TXT = $(#myTextbox);
  VAR FUNC =功能(){
    txt.val(txt.val()代替(/ \ S / G,''));
  }
  txt.keyup(FUNC).blur(FUNC);
});
 

您必须另行办理模糊事件,因为用户可以使用右键菜单粘贴;)

How could I, on the fly, remove spaces entered into a textbox while the person is typing?

解决方案 网页中的文本框无法输入文字怎么办

$(function() {
  var txt = $("#myTextbox");
  var func = function() {
    txt.val(txt.val().replace(/\s/g, ''));
  }
  txt.keyup(func).blur(func);
});

You have to additionally handle the blur event because user could use context menu to paste ;)