我有这个 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 请求现在正在工作)
首先要跳出的是:
<ul class="statuses">
and
$('#statuses')
... jQuery 中的 # 符号是 id 选择器(与 CSS 相同)。自从你的<ul>
被设定为class="statuses"
那么你需要使用类选择器:
$('.statuses')
仅此一点就会破坏你所有的 jQuery
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)