我怎么可能,在飞行中,删除空格进入了一个文本框,而人是打字?
解决方案 $(函数(){
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 ;)