如何使1 +1 = 2而不是1 +1 = 11 [英] How to make 1 + 1 = 2 instead of 1 + 1 = 11

查看:100
本文介绍了如何使1 +1 = 2而不是1 +1 = 11的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试以数学方式添加数字,但它会一直在其后添加数字.

I am trying to add the number mathematically, but it keeps adding the number after it.

它获取ID号(begen),然后获取另一个div(kacbegen)内部的数字.

It takes the id number (begen), then it gets the number inside another div (kacbegen).

var begen = $(this).attr('id');
var kacbegen = $("#math" + begen).text();
var toplam = (kacbegen + 1);

alert(toplam);

但是,当进行数学运算(toplam)时,它会警告所有数字.如何在数学上加数字?

However, when doing the math (toplam), it alerts all the numbers.How to add the number mathematically ?

推荐答案

通过添加+将其转换为数字:

Convert it to number via adding a +:

var toplam = (+kacbegen + 1);

一元加号(+)

一元加号运算符位于其操作数之前,并求值为其操作数,但是尝试将其转换为数字(如果尚未转换为数字).

Unary plus (+)

The unary plus operator precedes its operand and evaluates to its operand but attempts to converts it into a number, if it isn't already.

这篇关于如何使1 +1 = 2而不是1 +1 = 11的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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