いくつかの数値を計算するために使用しているフォームがあります。フォームの最後の 3 つの入力フィールドは、電卓の結果を表示するため無効になっています。
次のjavascript/jqueryを使用して、ユーザーが編集可能なフィールドにコンマを追加していますが、これはうまく機能しますが、「結果」フィールドにコンマを追加する方法が見つからないようです:
$('input.seperator').change(function(event){
// skip for arrow keys
if(event.which >= 37 && event.which <= 40){
event.preventDefault();
}
var $this = $(this);
var num = $this.val().replace(/,/gi, "").split("").reverse().join("");
var num2 = RemoveRougeChar(num.replace(/(.{3})/g,"$1,").split("").reverse().join(""));
// the following line has been simplified. Revision history contains original.
$this.val(num2);
});
function RemoveRougeChar(convertString){
if(convertString.substring(0,1) == ","){
return convertString.substring(1, convertString.length)
}
return convertString;
}
これは私がフィールドに入力するために使用しているものです。基本的にフィールドは結果をドルで表示するため、3つの数字ごとにコンマを追加しようとしています:
$('#incorrect-payment').val(fieldK);
$('#correcting-payment').val(fieldL);
$('#total-cost').val(fieldM);