일련 번호를 더하여 합계를 만드는이 자바 스크립트가 있습니다. 그런 다음 일련의 숫자에서 가장 낮은 숫자를 찾아 전체에서 빼냅니다. 나는 사용자가 숫자 값을 입력하고 그 숫자를 방정식의 일부로 사용할 수 있기를 원한다. 먼저 코드를 작성한 다음 내가 시도한 것을 알려 드리겠습니다. 내가 추가하여 생각Javascript 방정식에서 양식 필드를 어떻게 참조합니까?
<input name="yellowtape" type="text" id="yellowtape" style="width:243px;">
:
var prices = [];
function remove(arr,itm){
var indx = arr.indexOf(itm);
if (indx !== -1){
arr.splice(indx,1);
}
}
function calculateSectedDues(checkbox, amount) {
if (checkbox.checked === true) {
prices.push(amount);
} else {
remove(prices, amount);
}
var total = 0;
for (var i = 0, len = prices.length; i < len; i++)
total += prices[i];
var min = prices.slice().sort(function(a,b){return a-b})[0];
if(typeof min === 'undefined') min = 0;
var withDiscount = total - min;
var discountAmount = withDiscount - total;
document.querySelector("#total").innerHTML = total;
document.querySelector("#discount").innerHTML = discountAmount;
document.querySelector("#newTotal").innerHTML = withDiscount;
document.getElementById("FinalTotal").value = withDiscount;
}
이것은 내가 방정식으로 끌어하도록 만든 양식 필드는 다음과 같습니다
이
은 덧셈과 뺄셈을 수행하는 스크립트입니다 :var withDiscount = total + yellowtape - min ;
작동하지만 작동하지 않을 수 있습니다. 폼 필드 'yellowtape'에 입력 한 숫자를 var withDiscount에 추가해야합니다.
사용'document.getElementById를 ("yellowtape을") 값 '보다는 단지 하나 개의'작은 제외하고 완벽하게 작동 –