我試圖訪問Update_Price
函數JavaScript文件時,我做任何更改select
標記,但不幸的是未捕獲的參考錯誤出現。這是我的代碼:未捕獲的ReferenceError:函數沒有與onchange定義
<!Doctype html>
<html>
<head>
<script type="text/javascript" src="Form-validation.js"></script>
</script>
</head>
<body>
<select class="Booking-Form-Group" id="combo-box" onchange="Update_Price()">
<option value="1">Single Room</option>
<option value="2">Double Room</option>
<option value="3">Twin Room </option>
<option value="4">Family Room</option>
<option value="5">Standard Room</option>
<option value="6">Meeting Hall</option>
<option value="7">Conference Room</option>
</select>
</body>
</html>
這是我的JavaScript代碼。
function Update_Price(){
alert('Warning');
var combo = document.getElementById('combo-box');
var index = combo.options[combo.selectedIndex].value;
var value = 0;
if (index == 1){
value = 15;
}
else if(index == 2 || index == 3){
value = 25;
}
else if(index == 4){
value = 40;
}
else if(index == 5){
value = 20;
}
else{
value = 60;
}
alert(value);
document.getElementById('price').innerHTML='Total Price is: '.value;
}
是'形式,validation.js'裏面的JS代碼? – gurvinder372
更改'document.getElementById('price')。innerHTML ='總價格:'.value;'到'document.getElementById('price')。innerHTML ='總價格:'+ value;' – Gintoki
把你的'腳本'標記到'body'的底部 –