在页面中有时候要求把所有input输入框去空格,尤其是最后的空格,写了个简单的办法:

$("input").change(function(){
$(this).val($(this).val().trim());
});


js中是没有trim方法的,自己写一个就好了,下面这个是去掉前后空格的:

String.prototype.trim=function(){
    return this.replace(/(^\s*)|(\s*$)/g, "");
 }

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-24
  • 2021-10-04
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-21
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案