我的老师让我们对创建一个函数的语法感到困惑,该函数完全替换数组内部对象中的段落和单词。
她也没有解释换行符语法以及如何正确连接换行符字符串。
我的函数语法做错了什么?
为什么我们使用函数而不是警报?
var button = document.getElementById("scinfo");
var states = {
"eachstate": [{
"Name": "North Carolina",
"Capital": "Raleigh",
"Population": "986,000",
"StateBird": "Who Cares"
},
{
"Name": "South Carolina",
"Capital": "Columbia",
"Population": "886,000",
"StateBird": "Hawk"
},
{
"Name": "Florida",
"Capital": "Tallahasee",
"Population": "975,000",
"StateBird": "Flamingo"
},
]
};
button.addEventListener("click", writestates, false);
function writestates() {
document.getElementById("StateInfo").innerHTML = "<p>Name: " + states.eachstate[0].name + "</p>" + "<p>" + "Capital: " +
states.eachstate[0].capital + "</p>" + "<p>" + "Bird: " + states.eachstate[0].bird + "</p>" + "<p>" + "Population: " +
states.eachstate[0].population + "</p>"
}
<!-- Create a button to write out ONLY SC information when clicked -->
<button id="states" type="button">SC Information</button>
<div class="showstate">
<h1>
South Carolina
</h1>
<p id="StateInfo">
This is where the new information should show up!
</p>
</div>
RISEBY
相关分类