我正在研究一個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