jquery – 如何从文本输入框中删除空格

我有以下jQuery shell工作:

$('.jq_noSpaces').on('change',function(){
    alert('you changed the value in the Box');
  });

我的表单属性是id =“username”name =“username”

如何使用以下jQuery替换函数自动更改从输入字段中删除空格?

str.replace(/\s+/g,'');

谢谢

解决方法

您可以使用以下语法:

$(this).val($(this).val().replace(/\s+/g,''));

在事件处理程序内部.

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: <span id=&quot...
jQuery 添加水印 <script src="../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...