var firefoxIngs = myText.replace(/ /g," ");
这是我的字符串:
"h a"//it has two empty spaces between h and a
代码后变成:
"h a"//it has one empty spaces between h and a
我希望它是
"h a"
为什么会发生这种情况以及如何解决?
var firefoxIngs = myText.replace(/ /g," ");
这是我的字符串:
"h a"//it has two empty spaces between h and a
代码后变成:
"h a"//it has one empty spaces between h and a
我希望它是
"h a"
为什么会发生这种情况以及如何解决?
这也有效
<script type="text/javascript">
function validate(){
str=document.getElementById("input").value;
str= str.replace(/\s/g, ' ');
console.log(str);
}
</script>
<input id="input" type="text"/>
<input type="button" onclick="validate()" />