次のように、タブ サイズが 2 スペースのテキストエリアがある場合:
<textarea id="source">
function add(a,b,c) {
return a+b+c;
}
</textarea>
結果は次のようになります。
<textarea id="source">
function add(a,b,c) {
return a+b+c;
}
</textarea>
2マスから4マスに変換する方法はありますか?
私はこれを試しています:
function convert(id,start,end) {
var myvalue = document.getElementById(id).value;
var myregex = new RegExp(" "*start,"g");
myvalue = myvalue.replace(myregex, " "*end);
}
<textarea id="source">
function add(a,b,c) {
return a+b+c;
}
</textarea>
<button onclick="convert('source',2,4)">Convert Tab Size 2 => 4</button>
ただし、タブのサイズは期待どおりに変換されません。なんで?