【发布时间】:2015-08-17 22:44:42
【问题描述】:
我有一个关于访问 JavaScript 对象的各个部分的问题。
var dictionary = {
"gimme": "༼ つ ◕_◕ ༽つ",
"umadbro": "¯\_(ツ)_/¯",
"lenny": "( ͡° ͜ʖ ͡°)"
}
所以我正在制作一个程序,当您输入相应的名称(gimme、umadbro、lenny 等)时,它会打印实际的 ascii/Uni 艺术,但是我不确定如何去做。这是我到目前为止的代码:
function checkCharacter() {
//Assign $ascii_box variable to ascii-box element
var $ascii_box = document.getElementById("ascii-box");
//Update value of $ascii_box_value everytime the text field changes
$ascii_box.on("input", function() {
var $ascii_box_value = $ascii_box.val();
});
//Check if value in text box is equal to a name in the dictionary object
//If equal, print the emote to the screen
if ($ascii_box_value === dictionary) {
}
}
我如何能够访问字典中的单词并在文本框中输入时将它们打印为表情?提前感谢您的帮助!
【问题讨论】:
-
使用
square brackets。 -
你也在混合 jquery 和标准 dom api。
-
谢谢,会的!您能否更详细地了解它如何使值更易于访问/修改?顺便说一下,这是一个 CodePen 项目。
标签: javascript jquery object