我正在研究一个WordPress插件“为我的评分”。此插件适用于单个帖子,但在博客页面上,当插件无法从哪个帖子ID完成点击时看到多个帖子时。它总是需要页面的firt post值。如何在jQuery脚本中获得动态帖子ID或值
我已经添加了ID和ID和类名来解决这个问题(例如:post_id $ post-> ID),但现在我被阻止以这种方式编辑jquery文件。
后投项目的PHP代码:
<input type=\"hidden\" id=\"post_id$post->ID\" value=\"" . $post->ID . "\" />
<div class=\"vote\">
<table>
<tr><td>
<a class=\"vote_up\" href=\"#\"></a></td>
<td>
<a class=\"vote_down\" href=\"#\"></a></td></tr>
<tr>
<td class=\"up_perc$post->ID\">" . get_percentage(1, $post->ID) ."%</td>
<td class=\"down_perc$post->ID\">" . get_percentage(2, $post->ID) . "% </td>
</tr>
</table></div>
<div class=\"vote_succ$post->ID\"></div>
jQuery的代码(投票支持,否决是很相同):
jQuery(document).ready(function($) {
$(".vote_up").click(function(e) {
e.preventDefault();
$.post('/wp-content/plugins/rate-my-whatever/rate.php', {vote_type: "1", post_id: $("#post_id1").val()}, function(data) {
$(".vote_succ1").html(data);
$.post('/wp-content/plugins/rate-my-whatever/rate.php', {action: "getPercentage", vote_type: "1", post_id: $("#post_id1").val()}, function(data2) {
$(".up_perc1").html(data2);
});
$.post('/wp-content/plugins/rate-my-whatever/rate.php', {action: "getPercentage", vote_type: "2", post_id: $("#post_id1").val()}, function(data3) {
$(".down_perc1").html(data3);
});
});
});
我把staticly “1” 后一些ID和类元素来检查我的问题将如何解决,它适用于Post 1的哪个ID和值是“1”,现在我需要替换#post_id,.vote_succ,.up_perc末尾的“1” ,.down_perc通过动态代码使其与PHP代码生成的动态元素一起工作。
感谢您的帮助。
非常感谢jfriend00,非常漂亮的工作,它的伟大工程;) – 2012-03-19 15:09:04
@FannyAuray - 因为它似乎你是新来的计算器,你明白,当你问一个问题,你会得到一个或更体面答案时,您最终应通过单击答案左侧的复选标记(仅在上/下箭头下方)将其中一个答案标记为“最佳答案”?这会为你和获得答案的人赢得一些声望点。 – jfriend00 2012-03-19 15:14:13
感谢您的信息,愉快地完成! – 2012-03-19 16:06:16