美文网首页
字符串去掉空格

字符串去掉空格

作者: 流觞小菜鸟 | 来源:发表于2019-12-26 16:37 被阅读0次

字符串去掉空格

第一种

var str="hello vue js css html"
    str=str.replace(/\s/g,"")
     console.log(str)

第二种

 var str="    hello vue js css html    "
str.trimLeft();  //将字符串最前面的空格修整掉。当在没有参数的情况下调用时,TrimLeft删除换行符,空格和tab字符。
str.trimRight();//消除从右侧起所遇到的所有空格字符

input自动去掉空格

第一种

<input type="text" onkeyup="this.value=this.value.replace(/^ +| +$/g,'')">

第二种

var str = document.getElementById("input").trim();

第三种vue提供的一个属性

<input type="text"  v-model.trim="userName">

相关文章

网友评论

      本文标题:字符串去掉空格

      本文链接:https://www.haomeiwen.com/subject/uekloctx.html