我是 Javascript 新手,我想使用 document.getElementById 来显示项目的值,在我的示例中,我想列出打印在 var= btsFrontEnd 中的名称,但我做错了。任何帮助都感激不尽。
谢谢你。 链接到我的小提琴
var btsFrontEnd = {
"employee-1": {
"name": "Name One",
"phone": "1234567890",
"email": "blah@blah.com"
},
"employee-2": {
"name": "Name Two",
"phone": "1234567890",
"email": "blah@blah."
}
};
var btsemployees = {
employees:[
{
"name": "Name One",
"phone": "1234567890",
"email": "blah@blah.com"
},
{
"name": "Name Two",
"phone": "1234567890",
"email": "blah@blah.com"
},
{
"name": "Name Three",
"phone": "1234567890",
"email": "blah@blah.com"
},
{
"name": "Name Four",
"phone": "1234567890",
"email": "blah@blah.com"
},
{
"name": "Name Five",
"phone": "1234567890",
"email": "blah@blah.com"
}
]
};
//First argument is our data structure (an object or an array
//Second argument is a callback (logic we apply to our data structure)
$.each(btsFrontEnd, function (key, value) {
console.log(key); //Prints this object's keys
console.log(value); //Prints immediate values from this object
console.log(btsFrontEnd[key]);
console.log(value.name);
document.getElementById("names").innerHTML.value;// This is what I am referring to, I would like it to appear in the p id="names"
});