javascript - jquery的问题?

标签 javascript jquery html image fadein

我有这个 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"> 

$('#statuses')

... jQuery 中的 # 符号是 id 选择器(与 CSS 相同)。自从你的<ul>设置为class="statuses"那么你需要使用类选择器:

$('.statuses')

仅仅这一点就会破坏你所有的 jQuery

关于javascript - jquery的问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3876084/

相关文章:

html - 布局右侧的空白区域

javascript - 如何在 HTML 页面中加载多个 javascript 文件

javascript - 如何从 JavaScript 中的任意字符串创建有效的文件名?

javascript - jQuery 函数不适用于表单提交

javascript - Bootstrap Popup - 将事件附加到动态弹出按钮

javascript - 如何使用jquery区分html/text按钮内容

javascript - 用于验证多个单词的单数正则表达式

javascript - 重叠图像在 Bootstrap 轮播淡入淡出时缓慢交叉淡入淡出

html - 内容 div 中的填充问题

JavaScript - 插入 HTML 的内容部分