【发布时间】:2010-10-07 04:00:13
【问题描述】:
我有这个 jquery 问题我已经有好几天了,我对此很陌生,所以请原谅我在这个主题上的愚蠢。谢谢:))
html代码:
<ul class="statuses">
<li id="set_23" class="message">
// this is meant to increase everytime you click the vote_up just like stackoverflow
<span class="vote_count">27</span>
<a href="#" class="vote_up"><img src="img/uparrow.png" /></a>
<a href="#" class="vote_down"><img src="img/downarrow.png" /></a>
</li>
</ul>
这是我的 jquery 代码:
$(document).ready(function() {
$('#statuses').delegate('.vote_up', 'click', function() {
//get the id
var the_id = $(this).closest('.message').attr('id').split('_').pop();
//the main ajax request
$.ajax({
type: "POST",
data: "action=vote_up&id=" + the_id,
url: "ajax/votes.php",
success: function (msg) {
// fade in the new vote_count
$(this).siblings("span.vote_count").html(msg).fadeIn();
// get the child <img> and set its src
$(this).children("img").attr("src", "img/uparrowActive.png");
}
});
});
});
编辑:jquery fade.in 和图像 src 的更改也不起作用,我是否引用了正确的跨度或类(ajax 请求现在正在工作)
【问题讨论】:
-
?抱歉,我更新了问题,我忘了我有 php varibale
-
问题出在哪里?设置后 console.log(the_id) 会发生什么? POST 调用发送的数据是什么?
-
只需将您的代码放在 jsfiddle 上,这样人们就可以一键查看它的运行情况。
-
好的,谢谢@user257493,下次我会这样做,再次感谢
-
@getaway - 虽然你的头衔很差,但这还不错。但是您从未在帖子中真正提出过问题。请确保我们这样做,这样我们就不必猜测您在问什么。它将帮助我们帮助您。谢谢! :)
标签: javascript jquery html image fadein