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"
なぜこれが起こっているのか、それを修正する方法は?
期待どおりに動作します
console.log("h a".replace(/ /g," "));
文字列では、1 つのスペースが欠落している可能性があります。
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()" />