jquery - 是否可以在 Jquery 中使用接收到的值中的“变量”?
问题描述
我有一个选择输入和以下功能:
$(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)
})
我想提醒变量下的信息。
因此,改为警告标签文本(例如波兰)我想使用这个名称下的可验证(返回有关某个国家/地区的信息)。
有可能做到吗?
先感谢您。
解决方案
是的你可以 !我建议使用 object type 。所以尝试如下
$(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)
})
推荐阅读
- c# - 如何从 C# 中的 custom.config 文件中检索键值
- doxygen - Doxygen ,仅为添加/更新的 api 生成文档
- c# - Azure 存储未找到 csv 文件
- matlab - 一维向量 Matlab 的逆
- visual-studio - 使用 msbuild 命令行跳过依赖项 wixproject
- java - 无法使用 EWS API [SOAP 请求] 将 Exchange 帐户的电子邮件列入白名单
- javafx - Corretto 是否支持 javaFX?
- ios - Swift 中基于泛型的返回类
- python - python中列表的二进制搜索
- cakephp - cakephp 3 路由匹配 /*.php