Javascript 从用户输入获取JS对象数据

Javascript 从用户输入获取JS对象数据,javascript,html,object,search,user-input,Javascript,Html,Object,Search,User Input,接受条件:输入姓名,并在单击或按“返回”时将此人的分机返回到UI 我正在寻找关于如何让这个工作的建议 搜索函数 变量扩展列表={ 艾比:“8845”, 大卫:“8871”, 吉姆:“8890”, 刘易斯:“8804”, }; var returnLookUp=函数(){ var getInfo=document.getElementById(“此搜索”); var SearchInfo=thisSearch.value; /*......?*/ } 发现 未定义明确的按钮类型。因此,默认情

接受条件:输入姓名,并在单击或按“返回”时将此人的分机返回到UI

我正在寻找关于如何让这个工作的建议


搜索函数
变量扩展列表={
艾比:“8845”,
大卫:“8871”,
吉姆:“8890”,
刘易斯:“8804”,
};
var returnLookUp=函数(){
var getInfo=document.getElementById(“此搜索”);
var SearchInfo=thisSearch.value;
/*......?*/
}
发现



未定义明确的按钮类型。因此,默认情况下,它将是按钮
type=“submit”
。在这种情况下,它将尝试提交表格。按钮
type=“button”
可以使用,也可以使用
preventDefault()

extensionList[thisSearch.value]
用于从对象获取键的值,
extensionList
是对象,
thisSearch.value
将是与对象键相同的输入

var扩展列表={
艾比:“8845”,
大卫:“8871”,
吉姆:“8890”,
刘易斯:“8804”,
};
var returnLookUp=函数(e){
e、 预防默认值();
var getInfo=document.getElementById(“此搜索”);
document.getElementById(“output”).value=extensionList[thisSearch.value];
}

发现



返回扩展列表[SearchInfo]如果我输入名称“David”,我希望页面返回他的扩展名8871。我可以通过使用console.log(extensionList.Jim)从extensionList对象获取信息,但我无法执行类似console.log(extensionList.SearchInfo)的操作。请重新阅读我的代码。不是
extensionList.SearchInfo
,而是
extensionList[SearchInfo]
。如果
searchInfo='Jim'
它将等同于
extensionList[“Jim”]
,它与
extensionList.Jim
<html>
    <head>
        <title>SearchFunction</title>
    </head>
    <body>
        <script type="text/javascript">

            var extensionList = {

                Abby: '8845',   
                David: '8871',  
                Jim: '8890', 
                Lewis: '8804',
            };

            var returnLookUp = function(){
                var getInfo = document.getElementById("thisSearch");
                var SearchInfo = thisSearch.value;
                /*......?*/
            }

        </script>
        <form>
            <input id="thisSearch" type="text" placeholder="enter name">
            <button onClick = "returnLookUp();">Find</button>
            <input id="output" name="output" type="text" size="30">
            <br><br>
        </form>

    </body>
</html>