<!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>&lt;script&gt;
	var count = 0;
	var clickBtn = document.getElementById('clickBtn');
	var countEl = document.getElementById('count');

	clickBtn.addEventListener('click', function() {
		count++;
		countEl.innerHTML = count;
	});
&lt;/script&gt;
</code></pre>
</body>
</html>
HTML Clicker Example Code: Increase Counter with Button

原文地址: https://www.cveoy.top/t/topic/lsuR 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录