我无法在 mousedownevent 上生成 1-100 的 10 个随机整数。另外我需要在表格行中显示每个,我是计算机编程的新手,我不知道我犯了什么错误。
这是我的代码:
function process() {
'use strict';
var ara = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
var index;
var output = '<tr>';
for (var i = 0; i < 1 0; i++) {
index = Math.floor(Math.random() * 100);
output += '<td>' + ara[index] + '</td>';
}
output += '</tr>';
document.getElementById('numbers').innerHtML = output;
}
function init() {
'use strict';
document.getElementById('showarray').onmousedown = process;
} // End of init() function
window.onload = init;
Id 编号是一个表格标签,id 显示数组是 H3 标签,我必须单击才能获取 10 个整数
这是HTML
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>assignment2.html</title>
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link rel="stylesheet" href="css/styles.css">
</head>
<body>
<!-- assignment2.html -->
<h2>10 Random Integers from 1 to 100</h2>
<h3 id='showarray'>Mouse down here to show integers in table below</h3>
<table id="numbers" border="2"></table>
<span id="show5th">The fifth element is ?</span>
<script src="js/assignment2.js"></script>
</body>
</html>
jsfiddle和固定10
_innerHTML