我们有一个页面,人们可以在其中发表评论。在任何特定页面上可能有 6 条评论。
我有的是在每个div中,有一个report link,让其他成员可以report这个帖子。我想要实现的目标非常复杂,但想知道是否有人可以提供帮助。
每篇文章,都有这样的报告链接:
<span class="reportThisLink">
<a href="report">Report</a>
</span>
我想做的是为每个链接(动态)添加一个 ID,以便每个评论都有自己的通用 ID。 类似于:class="reportThisLink"id="article2"
无论如何,我的问题是:
I want onclick to grab the url of the page, and the ID of the link. And post this info in disabled form fields. ( within a Modal Window ).
I want to also HIDE the review with a placer div, until the matter has been reviewed.
所以问题是,我如何获取点击时的 PAGE URL 和点击链接的 ID,并将它们发布到禁用的表单字段中?
如果作为奖励有人知道如何隐藏已报告的 div,我很乐意进一步调查。
典型的页面 URL 是:http://anywebsite.com/reviews/state/suburb/
最佳答案
听起来您希望在页面上使用 Javascript 执行此操作?如果您要将事件附加到链接。
如果是这样,那么我个人会使用 jQuery 并执行如下操作:
HTML
<span class="reportThisLink">
<a href="report" id="102" class="reportlink">Report</a>
</span>
Javascript
$(document).ready(function(){
$('.reportlink').click(function(){
var docUrl = document.URL; // your current url
var badLink = $(this).attr('id'); // the id of the clicked link
// Now you could do the rest as you said
// and put these values into hidden form fields.
// Or you could submit them via "post" using jQuery...
$.post('reporthandler.php', {offendingUrl: docUrl, offendingLink: badLink});
});
});
警告
我还没有测试拼写错误,因此请注意可能存在一些错误。有关更多信息,值得查看 jQuery:http://www.jquery.com
关于php - 报告链接帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6880284/