且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

javascript-如何通过将用户输入与其键相匹配来显示对象的值?

更新时间:2023-09-06 22:15:28

调用对象以获取键值对后,可以使用[]:

You can use [] after calling the object to get the key value pair:

GardinerToUnicodeCodePoint[userInput]

将您的代码更改为:

    var userInput = $("#userInput").val; /*for example 'A1'*/
    if (userInput in GardinerToUnicodeCodePoint) {
        alert(GardinerToUnicodeCodePoint[userInput]);
    } else {
        alert("No code found!");
    }

请参阅jsfiddle: https://jsfiddle.net/wy70s3gj/

See jsfiddle: https://jsfiddle.net/wy70s3gj/