You can add a refresh button on the verification code image and click the button to get the verification code again. Here is an example:
<!-- 在 HTML 页面中引用验证码图片,使用 JavaScript 给其添加点击事件 -->
<div>
<img id="captcha" src="captcha.php" alt="验证码">
<button onclick="refreshCaptcha()">刷新</button>
</div>
<!-- 提交表单时发送验证码字符串 -->
<input type="text" name="captcha">
<script>
function refreshCaptcha() {
document.querySelector('#captcha').src = 'captcha.php?' + Date.now();
}
</script>In the code above, we add an ID to the captcha image and then add a click event to it using JavaScript. When the "Refresh" button is clicked, the refreshCaptcha() function will be called, which will obtain the verification code image object and refresh the verification code image by adding a random parameter to it. The user can then see the new verification code and enter it.