您好我已经写了一个简单的表格数学设置,但我意识到它需要改变,基本上我需要创建的是检测到如果成人票是10或更高,每张票价7美元而不是10美元,但是如果每张票的9或以下仍然是10美元
<form name="newshow" id="newshow" action="test.php" method="post"
oninput="totalamount.value = Math.round(adult.value * 10)
+ Math.round(student.value * 7); changedue.value =
Math.round(moneygiven.value - totalamount.value);">
<fieldset>
<select name="showtime" >
<option value="" disabled="disabled" selected="selected">Performance</option>
<option value='1' type="number" >Show 1 </option>
<option value='2' type="number" >Show 2 </option>
<option value='3' type="number" >Show 3 </option>
</select>
<h4>Ammount of Adults</h4>
<input name="adult" id="adult" type="number" >
<br />
<h4>Ammount of Students</h4>
<input name="student" type="number" >
<br />
<h4>Money Owed</h4>
<input name="totalamount" readonly="1">
<br />
<h4>Money Given</h4>
<input name="moneygiven" type="number" >
<h4>Change due</h4>
<input name="changedue" readonly="1">
<input type="submit" />
</fieldset>
</form>
&#13;
我不确定从哪里开始,但我假设这可以通过脚本而不是&#34; oninput&#34;来完成。我目前正在使用
答案 0 :(得分:0)
试试这个。这将检查成人票是否> = 10
<form name="newshow" id="newshow" action="test.php" method="post"
oninput="totalamount.value = ((adult.value >= 10) ? Math.round(adult.value * 7) : Math.round(adult.value * 10)) + Math.round(student.value * 7);
changedue.value = Math.round(moneygiven.value - totalamount.value);">
<fieldset>
<select name="showtime" >
<option value="" disabled="disabled" selected="selected">Performance</option>
<option value='1' type="number" >Show 1 </option>
<option value='2' type="number" >Show 2 </option>
<option value='3' type="number" >Show 3 </option>
</select>
<h4>Ammount of Adults</h4>
<input name="adult" id="adult" type="number" >
<br />
<h4>Ammount of Students</h4>
<input name="student" type="number" >
<br />
<h4>Money Owed</h4>
<input name="totalamount" readonly="1">
<br />
<h4>Money Given</h4>
<input name="moneygiven" type="number" >
<h4>Change due</h4>
<input name="changedue" readonly="1">
<input type="submit" />
</fieldset>
</form>