Py学习  »  Jquery

可以从Jquery中的接收值使用“variables”吗?

kibus90 • 4 年前 • 498 次点击  

我有一个选择输入和以下功能:

$(document).on('change','select#country',function(){
var Netherlands = "Code: NL. A currency in Netherlands is Euro (EUR)";
var Poland = "Code: PL. A currency in Poland is Polish Zloty (PLN)";
var xd = $(this).find('option:selected').text()
alert(xd) //use a var from received text (which equal to var)
})

我想提醒一下变量下面的信息。

所以,我想使用这个名字下的veriable(返回某个国家的信息)。

有可能吗?

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/56143
 
498 次点击  
文章 [ 1 ]  |  最新文章 4 年前
David Japan
Reply   •   1 楼
David Japan    4 年前

是的,你可以!我建议使用对象类型。所以试试下面的

$(document).on('change','select#country',function(){
var CodeList = {
  Netherlands : "Code: NL. A currency in Netherlands is Euro (EUR)",
  Poland      : "Code: PL. A currency in Poland is Polish Zloty (PLN)"
}
var xd = $(this).find('option:selected').text()
alert(CodeList[xd]) //use a var from received text (which equal to var)
})