추가를 사용하여 해결할 var 합계를 얻을 수 없습니다. 곱셈 연산자로는 var total = subtotal * sales_tax 을 사용할 수 있지만 + 부호 추가 연산자는 사용할 수 없습니다. var total = subtotal + sales_tax. 어떤 도움이라도 대단히 감사 할 것입니다.Javascript : 더하기 연산자를 사용하기 위해 변수 합계를 얻을 수 없습니다.
var calculate_click = function() {
var subtotal = parseFloat(document.getElementById("subtotal").value).toFixed(3);
var taxRate = parseFloat(document.getElementById("tax_rate").value).toFixed(3);
if (isNaN(subtotal) || isNaN(taxRate)) {
}
else {
var sales_tax = (subtotal * taxRate/100);
parseFloat(document.getElementById("sales_tax").value = sales_tax.toFixed(3));
var total = subtotal + sales_tax;
parseFloat(document.getElementById("total").value = total.toFixed(3));
}
}
당신이 그것을 작동하지 않는 말, 출력은 무엇인가? 실행중인 예제 (JSFiddle 또는 StackOverflow의 새 코드 편집기)에 연결할 수 있습니까? –
또한 필드 값을 설정 한 코드에서'parseFloat()'를 호출하는 것은 의미가 없습니다. – Pointy
입력 값을'parseFloat'에 넣는 이유는 무엇입니까? – Tommi