我在下面有这个简单的代码。我正在尝试查询输入框中输入的任何形状的名称。我可以正确地在函数中传递参数,但是当我尝试使用参数查询它时,它会导致我出错。
console.log(shape); //I'm getting the right input as parameter
console.log(shapes.shape.name); //not successful using passed parameter.
//下面的代码
<div id="page">
<input type="text" id="getShape"/>
<input type="button" onClick="getShapeDetails()" />
</div>
<script>
shapes = {
"circle" : {"name":"circle", "sides":"0", "color":"yellow"},
"triangle" : {"name":"triangle", "sides":"3", "color":"red"},
"square" : {"name":"square", "sides":"4", "color":"blue"},
};
function getShapeDetails(){
var getShape = document.getElementById("getShape").value;
function getShapesDetail(shape){
console.log(shape);
console.log(shapes.shape.name);
}
getShapesDetail(getShape);
}
</script>