我在這裏有一個工作代碼,可以讓用戶輸入內容並立即顯示輸出,但是我想創建一個由按鈕觸發的功能,該按鈕可以清除輸出區域本身。這可能與我的代碼?清除輸出區域
這裏是我的完整代碼:
<html>
<meta charset="UTF-8">
<head>
<title>Sample Array</title>
<script>var index = 0;</script>
</head>
<body>
Input:
<input type="text" id="input">
<input type="button" value="GO" onClick="press(input.value)">
<p id = "display">
<script>
var sample = new Array();
function press(Number)
{
if (Number != '')
{
sample[index] = Number;
document.getElementById("display").innerHTML += sample[index] + "<br>";
index++;
}
else
alert("empty");
document.getElementById('input').value = '';
}
</script>
</body>
</html>
什麼是輸出區域? –
頁面本身是輸入框和按鈕下方的輸出區域。 –
你的意思是清除內容中的
標籤。我對嗎? –