开发者

Is it possible to use jquery to add numbers taken from mysql?

Hey guys quick question. I have a div that gets assigned a number to its id that is taken from the database on page load. I am trying to use jquery to add 1 to that number but for example if the number was 70 to be开发者_JS百科gin with it just becomes 701. Anyone know what I am doing wrong?

echo "<div class=\"total\" id=\"$total\">$total</div>";

var total=$(".total").attr("id");

var newtotal=total+1;
$('.total').html(newtotal);


   var newtotal=parseInt(total)+1;

Use parseInt to convert the String into an integer.


You need to use parseInt()

echo "<div class=\"total\" id=\"$total\">$total</div>";

var total = parseInt($(".total").attr("id"));

var newtotal=total+1;
$('.total').html(newtotal);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜