diff --git a/static/public/forgot.html b/static/public/forgot.html
index 8d19c9d..c87f688 100644
--- a/static/public/forgot.html
+++ b/static/public/forgot.html
@@ -63,11 +63,11 @@ let cooldownTimer = null; // 重发倒计时(与服务端 smtp 同邮箱 60s
let captchaToken = '';
let captchaLoading = false; // 防重复点击:加载中忽略再次触发
-async function refreshCaptcha() {
+async function refreshCaptcha(preserveInput) {
if (captchaLoading) return;
captchaLoading = true;
captchaToken = '';
- captchaInput.value = ''; // 开始刷新时清空输入,避免用户误用旧验证码
+ if (!preserveInput) captchaInput.value = ''; // 默认清空输入;preserveInput=true 时保留(获取验证码后)
captchaImg.style.opacity = '0.5'; // 视觉提示:正在刷新
try {
const res = await fetch('/captcha/image', { cache: 'no-store' });
@@ -267,8 +267,9 @@ getCodeButton.addEventListener('click', async function () {
codeTip.classList.add('tip-red');
if (httpStatus === 429) startResendCooldown(60); // 命中冷却/限流,倒计时对齐
} finally {
- // CAPTCHA Token 一次性消费,无论成败都刷新
- refreshCaptcha();
+ // CAPTCHA Token 一次性消费,无论成败都刷新图形验证码;
+ // 刷新时保留已输入的图形验证码答案,避免误清空用户输入
+ refreshCaptcha(true);
if (!cooldownTimer) getCodeButton.disabled = false;
}
});
diff --git a/static/public/js/register.js b/static/public/js/register.js
index 45898ee..e44dccb 100644
--- a/static/public/js/register.js
+++ b/static/public/js/register.js
@@ -19,11 +19,11 @@ let cooldownTimer = null; // 重发倒计时(与服务端同邮箱 60s 发送
let captchaToken = '';
let captchaLoading = false; // 防重复点击:加载中忽略再次触发
-async function refreshCaptcha() {
+async function refreshCaptcha(preserveInput) {
if (captchaLoading) return;
captchaLoading = true;
captchaToken = '';
- captchaInput.value = ''; // 开始刷新时清空输入,避免用户误用旧验证码
+ if (!preserveInput) captchaInput.value = ''; // 默认清空输入;preserveInput=true 时保留(获取验证码后)
captchaImg.style.opacity = '0.5'; // 视觉提示:正在刷新
try {
const res = await fetch('/captcha/image', { cache: 'no-store' });
@@ -222,8 +222,9 @@ getCodeButton.addEventListener('click', async function () {
codeTip.classList.add('tip-red');
if (httpStatus === 429) startResendCooldown(60); // 命中冷却/限流,倒计时对齐
} finally {
- // CAPTCHA Token 一次性消费,无论成败都刷新
- refreshCaptcha();
+ // CAPTCHA Token 一次性消费,无论成败都刷新图形验证码;
+ // 刷新时保留已输入的图形验证码答案,避免误清空用户输入
+ refreshCaptcha(true);
if (!cooldownTimer) getCodeButton.disabled = false;
}
});