我有三个事件侦听器,在第三个控制台中,我在前一个事件侦听器中记录了变量。
我认为这不可能,因为变量是函数作用域?
干杯
乔
https://jsfiddle.net/c3wb1vzr/
HTML
<h3>Bill</h3>
£ <input id="billAmount" type="number" placeholder="Bill amount">
<h3>Service</h3>
<select>
<option>Excellent</option>
<option>Very Good</option>
<option>Good</option>
<option>Ok</option>
<option>Poor</option>
<option>Very Poor</option>
</select>
<h3>How many sharing?</h3>
<input id="totalSharing" type="number" placeholder="Number of people"> people
<button id="calculateTotal">Calculate</button>
JS
document.getElementById('billAmount').addEventListener('input', function(e) {
var total = e.target.value;
});
document.getElementById('totalSharing').addEventListener('input', function(e) {
var totalSharing = e.target.value;
});
document.getElementById('calculateTotal').addEventListener('click', function() {
console.log(totalSharing.value);
});