我正在尝试创建一个按钮,当您单击该按钮时,它将显示文本区域的值。但是相反,我没有定义。您知道我的代码有什么问题吗?
<body>
<textarea id="textarea" name="" cols="60" rows="8"></textarea>
<button id="submitButton">Submit</button>
</body>
<script>
var answer = document.getElementById('textarea');
submitButton.addEventListener('click', showHistory)
function showHistory() {
alert(answer.value);
}
</script>
此行submitButton.addEventListener('click', showHistory)
的问题
var answer = document.getElementById('textarea');
document.getElementById('submitButton').addEventListener('click', showHistory)
function showHistory() {
alert(answer.value);
}
<textarea id="textarea" name="" cols="60" rows="8"></textarea>
<button id="submitButton">Submit</button>