如何在javascript中引用另一个变量/参数中的变量?
我想用一个函数重构我的javascript代码 ingos-是该公司的名称,我有第五个类似的代码部分如何在javascript中引用另一个变量/参数中的变量?,javascript,jquery,Javascript,Jquery,我想用一个函数重构我的javascript代码 ingos-是该公司的名称,我有第五个类似的代码部分 $('#ingosRegularPrice').removeClass("inactive"); $('#ingosActivePrice').removeClass("inactive"); $('#ingosRegularPrice .btn span').text(ingosPrice); $('#ingosActivePrice .btn span').t
$('#ingosRegularPrice').removeClass("inactive");
$('#ingosActivePrice').removeClass("inactive");
$('#ingosRegularPrice .btn span').text(ingosPrice);
$('#ingosActivePrice .btn span').text(ingosPrice * params.ingos.programB);
有点像
function setPriceActive(company){
$('#'+ company + 'RegularPrice').removeClass("inactive");
$('#'+ company + 'ActivePrice').removeClass("inactive");
$('#'+ company + 'RegularPrice .btn span').text(companyPrice);
$('#'+ company + 'ActivePrice .btn span').text(ingosPrice * params.company.programB);
}
但我得到一个引用错误,即“company”变量不存在。如何将函数params用作文本引用和其他变量名的一部分
感谢更改:
params.company.programB
致:
真的吗?没有值得张贴的重复内容?;)你的意思是params[公司]。程序球问题在某种程度上是重复的。然而,用点符号是很清楚的。谢谢我只是不知道这个问题是如何表述的。变量名呢?文本(ingosPrice)。我该如何使用(公司价格)?Sergey,
这个[company+“Price”]
应该可以用这将是上下文,具体取决于您在何处声明变量IgnoPrice。您可以在jQuery选择器中使用变量。请验证您通过的公司是否正确
params[company].programB