我在确定如何将javascript变量输出到表格时遇到了问题。 我的javascript变量写在这个函数中。如何取出这些变量并将其显示在表格中?
function displayTotal(){
var beforenoonprice = 6.00; // CHANGE THE PRICE OF THE BEFORE NOON TICKET
var matineeprice = 8.50; // CHANGE THE PRICE OF THE MATINEE TICKET
var seniorprice = 9.50; // CHANGE THE PRICE OF THE SENIOR TICKET
var militaryprice = 9.00; // CHANGE THE PRICE OF THE MILITARY TICKET
var studentdayprice = 7.50; // CHANGE THE PRICE OF THE STUDENT DAY TICKET
var seniordayprice = 6.00; // CHANGE THE PRICE OF THE SENIOR DAY TICKET
var adultprice = 10.50; // CHANGE THE PRICE OF THE ADULT TICKET
var childprice = 7.50; // CHANGE THE PRICE OF THE CHILD TICKET
var threeDprice = 3.50; // CHANGE THE PRICE OF THE REGULAR 3D PRICE
var imaxPrice = 4.50; // CHANGE THE PRICE OF THE IMAX TICKET
var imax3dPrice = 5.50; // CHANGE THE PRICE OF THE IMAX 3D TICKET
//PRICE CHANGE EDIT ENDS HERE
var beforenoon = Number(document.getElementById('beforeNoon').value) || 0;
var beforenooncost = beforenoon * beforenoonprice;
var matinee = Number(document.getElementById('matinee').value) || 0;
var matineecost = matinee * matineeprice;
var senior = Number(document.getElementById('seniorTicket').value) || 0;
var seniorcost = senior * seniorprice;
var Military = Number(document.getElementById('militaryTicket').value) || 0;
var militarycost = Military * militaryprice;
var StudentDay = Number(document.getElementById('studentdayTicket').value) || 0;
var studentdaycost = StudentDay * studentdayprice;
var seniorDay = Number(document.getElementById('seniordayTicket').value) || 0;
var seniordaycost = seniorDay * seniordayprice;
var Adult = Number(document.getElementById('adultTicket').value) || 0;
var adultcost = Adult * adultprice
var child = Number(document.getElementById('childTicket').value) || 0;
var childcost = child * childprice;
var threeD = Number(document.getElementById('threed').value) || 0;
var threeDcost = threeD * threeDprice;
var Imax = Number(document.getElementById('imax').value) || 0;
var imaxCost = Imax * imaxPrice;
var Imax3d = Number(document.getElementById('imax3d').value) || 0;
var imax3dCost = Imax3d * imax3dPrice;
var total = childcost+adultcost+militarycost+seniorcost+studentdaycost+seniordaycost+threeDcost+imaxCost+imax3dCost+beforenooncost+matineecost;
document.getElementById('calculate').innerHTML = total.toFixed(2);
}
这是表
<div id="priceUpdateTable">
<table border="1" style="width:500px" >
<tr>
<td height="30">Price Type</td>
<td>Current Price</td>
<td>New Price</td>
</tr>
<tr>
<td height="30">Before Noon</td>
<td><script>document.write(beforenoonprice);</script></td>
<td>nP</td>
</tr>
<td height="30">Matinee</td>
<td>cP</td>
<td>nP</td>
</tr>
<td height="30">Adult</td>
<td>cP</td>
<td>nP</td>
</tr>
<td height="30"> Child</td>
<td>cP</td>
<td>nP</td>
</tr>
<td height="30">Senior</td>
<td>cP</td>
<td>nP</td>
</tr>
<td height="30">Military</td>
<td>cP</td>
<td>nP</td>
</tr>
<td height="30">Senior Day</td>
<td>cP</td>
<td>nP</td>
</tr>
<td height="30">Student Day</td>
<td>cP</td>
<td>nP</td>
</tr>
</table>
</div>
答案 0 :(得分:0)
您可以简单地在表格中记录变量名称。
例如:
<td><script>variable name to print goes here</script></td>