0
我有以下代碼。以格式編號爲貨幣的Javascript
<select id="cage_options">
<option>Please select</option>
<option value="2,63330">option1</option>
<option value="3,13300">option2</option>
<option value="4,2000.00">option3</option>
</select>
<input id="cage_labor_estimate" disabled>
<script>
function format(n) {
return n.toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1,");
}
document.getElementById("cage_options").addEventListener("change", cageOptionFunction);
function cageOptionFunction() {
select=document.getElementById('cage_options').value.split(',');
cage_option = select[1];
document.getElementById("cage_labor_estimate").value = format(cage_option);
}
</script>
我試圖在禁用輸入框中輸入輸出格式在當前的格式,但出現以下錯誤:
TypeError: n.toFixed is not a function. (In 'n.toFixed(2)', 'n.toFixed' is undefined)
誰能幫助?
感謝,
約翰
因爲你有一個字符串,而不是數量。 – epascarello