HTML Clicker Example Code: Increase Counter with Button
<!DOCTYPE html>
<html>
<head>
<title>Clicker Example</title>
<style>
button {
font-size: 24px;
padding: 12px 24px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}
</style>
</head>
<body>
<h1>Clicker Example</h1>
<p>Click the button to increase the count:</p>
<button id='clickBtn'>Click Me</button>
<p>Count: <span id='count'>0</span></p>
<pre><code><script>
var count = 0;
var clickBtn = document.getElementById('clickBtn');
var countEl = document.getElementById('count');
clickBtn.addEventListener('click', function() {
count++;
countEl.innerHTML = count;
});
</script>
</code></pre>
</body>
</html>
原文地址: https://www.cveoy.top/t/topic/lsuR 著作权归作者所有。请勿转载和采集!