私はいくつかの価格を合計してすべての価格入力に入れたいと思いますが、その機能は数値を合計しません。互いに隣り合っている。文字列を数値に変更するコードはありますか?すべての価格は代わりに価格を集計するのではなく、お互いに価格を入れます
<html>
<label class="fa">ext modeling price</label>
<input type="number" class="form-control" onchange="allPrc();" id="model-
ext-price" placeholder= "0" ></input>
<br>
<label class="fa">int modeling price</label>
<input type="number" class="form-control" onchange="allPrc();" id="model-
int-price" placeholder= "0" ></input>
<hr class="hrline">
<label class="fa"> ext renderign price</label>
<input type="number" class="form-control" onchange="allPrc();" id="render-
ext-price" placeholder= "0" ></input>
<br>
<label class="fa">int rendering price </label>
<input type="number" class="form-control" onchange="allPrc();" id="render-
int-price" placeholder= "0" y></input>
<hr class="hrline">
<label class="fa">pproduction price </label>
<input type="number" class="form-control" onchange="allPrc();"
id="pproduction-price" placeholder= "0" y></input>
<hr class="hrline">
<label class="fa"> All price </label>
<input type="number" class="form-control" id="All-price" placeholder= "0"
readonly></input>
</html>
<script>
document.getElementById ('model-ext-price').onchange = function() {allPrc();};
document.getElementById ('model-int-price').onchange = function() {allPrc();};
document.getElementById ('render-ext-price').onchange = function() {allPrc();};
document.getElementById ('render-int-price').onchange = function() {allPrc();};
document.getElementById ('pproduction-price').onchange = function() {allPrc();};
var allPrc = function() {
var Totalextmdl = document.getElementById ('model-ext-price').value,
Totalintmdl = document.getElementById ('model-int-price').value,
Totalextrndr = document.getElementById ('render-ext-price').value,
Totalintrndr = document.getElementById ('render-int-price').value,
Totalpp = document.getElementById ('pproduction-price').value,
TotalPrc = 0;
document.getElementById('All-price').value = TotalPrc;
var TotalPrc = Totalextmdl + Totalintmdl + Totalextrndr + Totalintrndr +
Totalpp;
document.getElementById('All-price').value = (TotalPrc>0 &&
TotalPrc!=='NaN')?TotalPrc:0;
};
</script>
それをJSはこれがあると信じているので、あなたのフィールドの値を変換する簡単な方法は、このように、あなたが最初にそれらを取得するとき単項
+
を使用することです文字列なので、プラス記号は基本的に文字列を連結します。数値を浮動小数点数に変換する必要があります: '' 'parseFloat(Totalextmdl = document.getElementById( 'model-ext-price')。value)' '' – Treast