This commit is contained in:
51
06_js-debug/uebungen/u14_counter-error/index.html
Normal file
51
06_js-debug/uebungen/u14_counter-error/index.html
Normal file
@@ -0,0 +1,51 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Counter Example</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/css/bootstrap.min.css" rel="stylesheet" />
|
||||
</head>
|
||||
<body>
|
||||
<div class="container py-5">
|
||||
<h1>Counter</h1>
|
||||
|
||||
<div class="row mt-4">
|
||||
<div class="col col-12 col-sm-10 col-lg-6">
|
||||
<div class="input-group mb-3">
|
||||
<span class="input-group-text" id="basic-addon1">Count:</span>
|
||||
<input type="text" id="count" class="form-control" value="0" readonly />
|
||||
</div>
|
||||
<button id="incrementButton" class="btn btn-primary w-100">Increment</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
'use strict';
|
||||
|
||||
(() => {
|
||||
// ===== DOM & VARS =====
|
||||
const countEl = document.querySelector('#count');
|
||||
const btnEl = document.querySelector('#incrementButton');
|
||||
|
||||
let counter = { count: 0 };
|
||||
|
||||
// ===== INIT =====
|
||||
const init = () => {
|
||||
btnEl.addEventListener('click', onClickIncrement);
|
||||
};
|
||||
|
||||
// ===== EVENT HANDLER =====
|
||||
function onClickIncrement() {
|
||||
let count = counter.count;
|
||||
count++;
|
||||
countEl.value = counter.count;
|
||||
}
|
||||
|
||||
// ===== CALL INIT =====
|
||||
init();
|
||||
})();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user