如何将页面内的链接添加到 JavaScript 回复链接?
嘿大家。我正在为我的网站编写博客系统脚本。所以我有这个功能:
<script language="javascript" type="text/javascript">
/* <![CDATA[ */
function reply(text) {
document.replyform.comment.value += text;
}
/* ]]> */
</script>
每个评论旁边都有这个链接:
<a href="#reply" onclick="reply('@<?php echo $name; ?>'); return false">Reply</a>
我的提交评论表单有标记的名称:
<a name="reply" id="reply">
<form method="post" action="/path/to/form" name="replyform">
// Etc...
<textarea name="comment" id="comment" rows="5" cols="10" class="f-comment"></textarea>
// Etc...
我想要实现的是,当用户单击“回复”某个评论时,不仅会将“@Name”添加到表单的文本框,但它也会跳转到表单(因为我已包含 href="#reply"
)。然而,这似乎不起作用,我假设 javascript onclick 会覆盖它?
当谈到 JavaScript 时,我完全一无所知!我应该怎么办?谢谢。
Hey all. I'm scripting a blogging system for my website. So I have this function:
<script language="javascript" type="text/javascript">
/* <![CDATA[ */
function reply(text) {
document.replyform.comment.value += text;
}
/* ]]> */
</script>
And this link next to each comment:
<a href="#reply" onclick="reply('@<?php echo $name; ?>'); return false">Reply</a>
And my submit comment form has the name tagged to it:
<a name="reply" id="reply">
<form method="post" action="/path/to/form" name="replyform">
// Etc...
<textarea name="comment" id="comment" rows="5" cols="10" class="f-comment"></textarea>
// Etc...
What I want to achieve is that when a user clicks on "Reply" to a certain comment, not only will it add a "@Name" to the form's textbox, but it'll also jump TO the form (as I have included href="#reply"
). However that doesn't seem to work and I'm assuming the javascript onclick overrides it?
When it comes to Javascript, I'm completely clueless! What should I do? Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我首先关闭回复锚点
然后删除
return false
链接。返回 false 会忽略链接 (href)。另一个解决方案是找出锚链接#reply
的位置并使用 JavaScript 滚动到那里。I would start by closing the reply anchor,
<a name="reply" id="reply"></a>
and then removing thereturn false
from the link. Returning false ignores the link (href). Another solution is to figure out the position of the anchor link#reply
and scroll there using javascript.