App下載
首頁javascriptparagraphJavascript Element - 如何將數(shù)組值分配給段標簽

Javascript Element - 如何將數(shù)組值分配給段標簽

我們想知道如何將數(shù)組值分配給段標簽。

<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'>
window.onload=function(){
    var answer = [
        "answer1",
        "answer2",
        "answer3",
        "answer4"
    ];
    document.getElementById("knap").onclick = function(){
        var panel = document.getElementById("answer");
        panel.innerHTML = answer[1];
    }
}
</script>
</head>
<body>
  <a id="knap" href="#">KNAP</a>
  <p id="answer"></p>
</body>
</html>