我需要这个来接受用户输入。取值并减去 1,以便可以调用和打印 5 个数组之一。如果选择 5,则打印所有 5 个数组;如果选择 3,则打印数组 0 到 2。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML1.0Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test2</title>
</head>
<body>
<input type="button" onclick="dutyarray()" value="Click">To see my top<input type="number" id="counter"> job duties here</input>
<br />
<p id="task">Duties</p>
<script>
function dutyarray()
{
var x = document.getElementById('counter').value;
x = parseInt(x);
var duty= new Array();
duty[0] = "Operate Equipment";
duty[1] = "Check for Water Damage";
duty[2] = "Check for Mold";
duty[3] = "Follow Insurance Procedure";
duty[4] = "Restore";
while(x >= 0; x - 1)
{
document.getElementById('task').innerHTML = duty[x] + <br>;
}
}
</script>