简体   繁体   English

选择并解析父div中的类

[英]Select and parseint of a class in parent div

im creating a blog post where onclick 'like' it finds the class for the number of likes and adds plus one to it. 我在onclick'like'上创建了一个博客帖子,它查找喜欢次数的类,并为其添加一个加号。 i think i can do this with parse int.. can anyone help me with this > 我想我可以通过解析int来做到这一点。

That is the HTML 那就是HTML

<span class="button_class"><a class="lik_right_stat_like" href="javascript:;">4255&nbsp;Likes&nbsp;&middot;</a></span>

This is the javascript.. onclick like works fine.. having trouble parsing the value for the above class and adding one to it. 这是javascript .. onclick之类的方法可以正常工作..无法解析上述类的值并将其添加到其中。 This is the jquery 这是jQuery

$(this).parent("div").find(".lik_right_stat_like").attr("alt", count) parseint()++;

(im quite new to jquery) (对jquery来说是很新的)

Try 尝试

$('.button_class').click(function () {
    $(this).parent("div").find(".lik_right_stat_like").text(function (idx, text) {
        return $.trim(text).replace(/^(\d+)/, function (str) {
            return (parseInt(text.match(/^(\d+)/), 10) || 0) + 1;
        });
    });
});

Demo: Fiddle 演示: 小提琴

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM