如何将变量值附加到另一个变量 [英] How to append variable value to another variable

查看:121
本文介绍了如何将变量值附加到另一个变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

var price11 = 100;

var i = 11;

var displayprice;

displayprice = price +'i';应该为显示价格分配100(价值11)。



是否可能。?



我尝试过:



var price11 = 100;

var i = 11;

var displayprice;

displayprice = price +'i';应该将100(价值11)分配给displayprice。



是否可能。?

var price11=100;
var i=11;
var displayprice;
displayprice= price+'i'; should assign 100(value of price11) to displayprice.

is it possible.?

What I have tried:

var price11=100;
var i=11;
var displayprice;
displayprice= price+'i'; should assign 100(value of price11) to displayprice.

is it possible.?

推荐答案

为什么你把单引号放在我身边了吗?我的猜测是你从某个地方复制了代码。所以,只需深呼吸,看看代码。



你在价格11和11中存储100个。所以,将它们加在一起,价格+ i。
Why did you put single quotes around i? My guess is you copied code from somewhere. So, just take a deep breath and look at the code.

You are storing 100 in price11 and 11 in i. So, add them together, price + i.


var price=100;
       var i=11;
       var displayprice;
       displayprice = price + 'i'; // this will result '100i', since the 'i' is considered as a string.
       displayprice = price + i; // this results 111, since both are of int type





在您的情况下,您应使用评估 [ ^ ],或角度Js表达式 [ ^ ]获取值为int



In your case, you shall use eval[^], or Angular Js Expression[^] to get the value as int

displayprice = price + eval('i'); // 111


这篇关于如何将变量值附加到另一个变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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