0
我想添加兩個已計算和格式化的輸入字段,沒有太大的運氣。我的代碼是:使用Javascript添加兩個輸入框
<input type='text' id='cage_linear_feet' value='83'>
<input type='text' id='cage_estimate' disabled>
<br>
<input type='text' id='cage_doors' value='3'>
<input type='text' id='doors_estimate' disabled>
<br>
<input type='text' id='cage_totals' disabled>
<script>
function format(n) {
return n.toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1,");
}
//Linear Feet Calculation
$(document).ready(LinearFeet);
document.getElementById('cage_linear_feet').addEventListener("keyup", LinearFeet);
var inputBox1 = document.getElementById('cage_linear_feet');
function LinearFeet(){
document.getElementById('cage_estimate').value = format(inputBox1.value*225);
}
//Doors Calculation
$(document).ready(CageDoors);
document.getElementById('cage_doors').addEventListener("keyup", CageDoors);
var inputBox2 = document.getElementById('cage_doors');
function CageDoors(){
document.getElementById('doors_estimate').value = format(inputBox2.value*1800);
}
</script>
如何實時添加cage_estimate和doors_estimate在一起,並顯示在cage_totals?
感謝,
約翰
輝煌!謝謝。我如何讓cage_totals以div的形式顯示?例如。
–@JohnHiggins document.getElementById(「divID」)。innerHTML = format(z); – Sanka
太好了,謝謝Sanka。剛剛解決了它,但是在我接觸之前更新了這篇文章!再次感謝。 –