[英]Javascript add value if checkbox is checked
<p>
<label for="hours">Learn JavaScript the Hardy Way’ - Complete e-book (Printed)</label>
<input type="number" min="0" id="chap7" name="hours" value="0">
</p>
<input type="checkbox" id="printed"/>Please tick if you would like a printed version<br />
<p class="post">Postage : <strong>£<output id="post">0</output></strong><p>
我想要一段javascript,以便在選中復選框時,郵資值為3.50。 但是,完整電子書的每份 3.50 美元。 所以它必須檢查數字框的值並按里面的值對其進行計時。
var chap7 = document.getElementById('chap7'), post = document.getElementById('post'), printed = document.getElementById('printed'); printed.addEventListener('change', function() { var quantity = parseInt(chap7.value, 10); post.value = printed.checked ? quantity * 3.5 : quantity; }, false); chap7.addEventListener('change', function() { post.value = parseInt(this.value, 10); });
<p> <label for="hours">Learn JavaScript the Hardy Way' - Complete e-book (Printed)</label> <input type="number" min="0" id="chap7" name="hours" value="0"> </p> <input type="checkbox" id="printed"/>Please tick if you would like a printed version<br /> <p class="post">Postage : <strong>£<output id="post">0</output></strong><p>
var chap7 = document.getElementById('chap7'), post = document.getElementById('post'); chap7.addEventListener('change', function(e) { var quantity = parseInt(chap7.value, 10); post.value = quantity * 3.5; }, false);
<p> <label for="hours">Learn JavaScript the Hardy Way' - Complete e-book (Printed)</label> <input type="number" min="0" id="chap7" name="hours" value="0"> </p> <p class="post">Postage : <strong>£<output id="post">0</output></strong><p>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.