我是Javascript新手,我想用document.getElementById來顯示項目的值,在我的例子中我想列出在var = btsFrontEnd中打印的名字,但我是做錯事。任何幫助都感激不盡。document.getElementById和Value
var btsFrontEnd = {
"employee-1": {
"name": "Name One",
"phone": "1234567890",
"email": "[email protected]"
},
"employee-2": {
"name": "Name Two",
"phone": "1234567890",
"email": "[email protected]"
}
};
var btsemployees = {
employees:[
{
"name": "Name One",
"phone": "1234567890",
"email": "[email protected]"
},
{
"name": "Name Two",
"phone": "1234567890",
"email": "[email protected]"
},
{
"name": "Name Three",
"phone": "1234567890",
"email": "[email protected]"
},
{
"name": "Name Four",
"phone": "1234567890",
"email": "[email protected]"
},
{
"name": "Name Five",
"phone": "1234567890",
"email": "[email protected]"
}
]
};
//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"
});
不要忘了選擇正確答案。 – sedran