javascript表单: - 如何在总数上给变量赋予不同的值

时间:2016-05-20 09:06:42

标签: javascript jquery html forms

嘿伙计们,所以基本上这个表格的目的是让这本书的每一章都是2英镑,然后整本书 - PDF将是8英镑,整本书的印刷费用是15英镑加上邮资和包装...... 。 我目前似乎无法得到最后两个价格和邮费不同章节将感谢任何帮助谢谢             

  <!--below is the text boxes which the user will use to define the amount of copies that they need -->

 Chapter 1 - Please enter how many copies you would like <br>

 <input class="textbox"type="Number" maxlength="24"  id="ch1" placeholder="0"><br><br>

 Chapter 2 - Please enter how many copies you would like <br>

 <input class="textbox"type="text" maxlength="24" id="ch2" placeholder="0"><br><br>

 Chapter 3 - Please enter how many copies you would like <br>

 <input class="textbox"type="text" maxlength="24" id="ch3" placeholder="0"><br><br>

 Chapter 4 - Please enter how many copies you would like <br>

 <input class="textbox"type="text" maxlength="24" id="ch4" placeholder="0"><br><br>

 Chapter 5 - Please enter how many copies you would like <br>

 <input class="textbox"type="text" maxlength="24" id="ch5" placeholder="0"><br><br>

Entire Book - PDF <br>

 <input class="textbox"type="text" maxlength="24" id="ebk" placeholder="0"><br><br>

Entire Book - Printed <br>

 <input class="textbox"type="text" maxlength="24" id="prnt" placeholder="0"><br><br>

  <b> Total :  <output id = "total"> 0 </output></b><br>

  <b> Postage :  <output id = "postage"> 0 </output></b><br>

  <b> Grand Total :  <output id = "grandtotal"> 0 </output></b><br>

  <!-- below is a button which calls the javascript file -->

    <input type="button" value="Calculate" id="calcu" onclick="calc()">

    <br><br>

<button type="submit">Payment</button>

 <script type="text/javascript">

function calc(){

 var ch1 = document.getElementById("ch1").value;

 var ch2 = document.getElementById("ch2").value;

 var ch3 = document.getElementById("ch3").value;

 var ch4 = document.getElementById("ch4").value;

 var ch5 = document.getElementById("ch5").value;

 var tot = document.getElementById("total");

 var post = document.getElementById("postage");

 var ebk = document.getElementById("bk1").value;

 var prnt = document.getElementById("prnt").value;

 tot = (Number(ch1) + Number(ch2) + Number(ch3) + Number(ch4) + Number(ch5))         * 2;

  if (prnt.value > = 0) {
   tot = Number(ebk) * 8;
   }


  document.getElementById("total").innerHTML = tot;

}

</script>

1 个答案:

答案 0 :(得分:0)

这应该有效:

var x = 10;
x += 5;

这将导致15。