开发者

After each times click an increasing number?

I want after each times click value 2011 an increasing number, how is it?

Example:

$('button').click(function() {
    var num = '2011';
    var out = num ++1;
    alert(num); // i want this ou开发者_C百科tput: 2012
});


var num = 2011;
$('button').click(function() {
    num++;
    alert(num); // i want this output: 2012
});


var num = '2011';
$('button').click(function() {
    num++;
    alert(num); // i want this output: 2012
});


Try this:

var num = '2011';
$('button').click(function() {
    var out = num++;
    alert(num);
});
  • var num must be outside of the function, otherwise it will be 2011 again every time the function is run.
  • num++1 should be num++.
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜