我遇到以下代码的问题。我试图从我的数组中获得一个随机字符串,以便在单击按钮时显示。简单的JavaScript代码不起作用
<script>
var button = document.getElementById("button");
var div = document.getElementById("box");
var text = document.getElementById("text");
var array=[ "thanks for clicking", "keep on clicking", "click one more time", "why do you keep on clicking me?", "stop clicking me!"];
function thing(){
var y = array[Math.floor((Math.random() * array.length)+1)];
text.value=y;
}
function what(){
text.value = "what";
}
</script>
<body>
<form>
<input type="button" id="button" value="click" onClick="what()" />
</form>
<form>
<input type="text" id="text" value="hey" />
</form>
</body>
错在你的代码? – showdev
将脚本移动到'
以下时,您是否曾打电话() –