按钮计数器改变造型

时间:2013-04-03 11:57:54

标签: jquery

实时查看:https://tornhq.com/WorkingOn/InteractiveMap/implementing.html
- 点击#Current标签或底部的其中一个国家

当前计数器,用于点击该链接时:

$(this).text(Number($(this).text()) + 1);

我尝试过很多东西,其中我认为这就是答案:

$(this).attr('p').text(Number($(this).attr('p').text()) + 1);
// OR
$(this).html(p).text(Number($(this).html(p).text()) + 1);

如何让按钮计数器不会上升,但保留为<p>分配的样式?

2 个答案:

答案 0 :(得分:1)

如果你想看到红色计数器上升:

试试这个

如果thisP,那么: $(this).text(function (i,n){return parseInt(n)+1;})

thisa所以:

$('p',$(this)).text(function (i,n){return parseInt(n)+1;}) //I think you need this

仅在控制台中测试 MATH 部分:

$("#Like-Earth p").text(function (i,n){return parseInt(n)+1;})

其中$("#Like-Earth p")应更改为我上面第一个选项中的一个。

答案 1 :(得分:0)

我认为您尝试做的是将标签中的当前数字替换为1。

var p = jQuery(this).find('p');
var newValue = ParseInt(p.html()) + 1;
jQuery(p).html(newValue);

我把它变成了int变量,但如果你想要的话,你可以将它组合成一长串代码。