fix: 回复按钮用 href=#respond + onclick 聚焦输入框

This commit is contained in:
2026-05-17 13:13:32 +08:00
parent 59c52a8bd6
commit 19f75da803
2 changed files with 43 additions and 48 deletions
+42 -47
View File
@@ -27,7 +27,7 @@ if (post_password_required()) return;
</div> </div>
<div class="comment-item__text"><?php echo esc_html($c->comment_content); ?></div> <div class="comment-item__text"><?php echo esc_html($c->comment_content); ?></div>
<div class="comment-item__reply"> <div class="comment-item__reply">
<a href="javascript:void(0)" onclick="replyTo(<?php echo $c->comment_ID; ?>)">回复</a> <a href="#respond" onclick="document.getElementById('comment_parent').value='<?php echo $c->comment_ID; ?>';document.getElementById('comment').focus()">回复</a>
</div> </div>
</li> </li>
<?php endforeach; ?> <?php endforeach; ?>
@@ -35,53 +35,48 @@ if (post_password_required()) return;
<?php endif; ?> <?php endif; ?>
<?php if (is_user_logged_in()) : ?> <?php if (is_user_logged_in()) : ?>
<?php comment_form(array( <div id="respond" class="comment-respond">
'title_reply' => '', <form id="commentform" class="comment-form" method="post" action="<?php echo site_url('/wp-comments-post.php'); ?>">
'comment_notes_before' => '', <textarea id="comment" name="comment" rows="3" placeholder="写点什么..." required></textarea>
'comment_notes_after' => '', <input type="hidden" name="comment_post_ID" value="<?php echo get_the_ID(); ?>">
'logged_in_as' => '', <input type="hidden" id="comment_parent" name="comment_parent" value="0">
'fields' => array(), <?php wp_nonce_field('comment_nonce_' . get_the_ID(), 'comment_nonce'); ?>
'comment_field' => '<textarea id="comment" name="comment" rows="3" placeholder="写点什么..." required></textarea>', <div class="form-submit">
'submit_button' => '<button type="submit" class="submit">落笔留痕</button>', <button type="submit" class="submit">落笔留痕</button>
'submit_field' => '<div class="form-submit">%1$s %2$s</div>', </div>
'label_submit' => '落笔留痕', </form>
)); ?>
<?php else : ?>
<form id="commentform-guest" class="comment-form" novalidate>
<textarea id="comment" name="comment" rows="3" placeholder="写点什么..." required></textarea>
<input type="hidden" id="comment_parent" name="comment_parent" value="0">
<div class="form-submit">
<button type="submit" class="submit">落笔留痕</button>
</div>
</form>
<?php endif; ?>
<?php if (!is_user_logged_in()) : ?>
<div id="login-modal" class="login-modal" style="display:none">
<div class="login-modal__content">
<p>登录后才能留言</p>
<button onclick="goLogin()" class="submit">去登录</button>
<button onclick="closeLoginModal()" class="cancel-btn">取消</button>
</div> </div>
</div> <?php else : ?>
<script> <div id="respond" class="comment-respond">
function replyTo(cid) { <form id="commentform-guest" class="comment-form" novalidate>
document.getElementById('comment_parent').value = cid; <textarea id="comment" name="comment" rows="3" placeholder="登录后写点什么..." required></textarea>
document.getElementById('comment').focus(); <input type="hidden" id="comment_parent" name="comment_parent" value="0">
} <div class="form-submit">
function goLogin() { <button type="submit" class="submit">落笔留痕</button>
window.location.href = '/wp-login.php?redirect_to=' + encodeURIComponent(window.location.href); </div>
} </form>
function closeLoginModal() { </div>
var m = document.getElementById('login-modal'); <div id="login-modal" class="login-modal">
if (m) m.style.display = 'none'; <div class="login-modal__content">
} <p>登录后才能留言</p>
document.getElementById('commentform-guest').addEventListener('submit', function(e) { <button onclick="goLogin()" class="submit">去登录</button>
e.preventDefault(); <button onclick="closeLoginModal()" class="cancel-btn">取消</button>
var m = document.getElementById('login-modal'); </div>
if (m) m.style.display = 'flex'; </div>
}); <script>
</script> document.getElementById('commentform-guest').addEventListener('submit', function(e) {
e.preventDefault();
var m = document.getElementById('login-modal');
if (m) m.style.display = 'flex';
});
function closeLoginModal() {
var m = document.getElementById('login-modal');
if (m) m.style.display = 'none';
}
function goLogin() {
window.location.href = '/wp-login.php?redirect_to=' + encodeURIComponent(window.location.href);
}
</script>
<?php endif; ?> <?php endif; ?>
</div> </div>
+1 -1
View File
@@ -1,6 +1,6 @@
/* /*
Theme Name: 空笺未寄 Theme Name: 空笺未寄
Version: 0.16.5 Version: 0.16.6
Requires at least: 6.0 Requires at least: 6.0
Requires PHP: 7.4 Requires PHP: 7.4
License: MIT License: MIT