如何使用Javascript / jQuery将数字字符串增加+1 [英] How to increment a numeric string by +1 with Javascript/jQuery

查看:753
本文介绍了如何使用Javascript / jQuery将数字字符串增加+1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下变量:

pageID = 7

我想在链接上增加这个数字:

I'd like to increment this number on a link:

$('#arrowRight').attr('href', 'page.html?='+pageID);

所以这输出7,我想附加链接说8.但如果我添加+1:

So this outputs 7, I'd like to append the link to say 8. But if I add +1:


$('#arrowRight')。attr('href','page.html?='+ pageID + 1 );

$('#arrowRight').attr('href', 'page.html?='+pageID+1);

我得到以下输出:1.html?= 71而不是8。

I get the following output: 1.html?=71 instead of 8.

如何将此数字增加为pageID + 1?

How can I increment this number to be pageID+1?

推荐答案

试试这个:

parseInt(pageID, 10) + 1

Accordint代码:

Accordint to your code:

$('#arrowRight').attr('href', 'page.html?='+ (parseInt(pageID, 10) + 1));

这篇关于如何使用Javascript / jQuery将数字字符串增加+1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆