日期:2014-05-16 浏览次数:20510 次
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> JavaScript 9*9 </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
</head>
<style>
td {
font-size: 12px;
}
</style>
<body leftmargin="0" topmargin="0">
<br />
<br />
<input type="text" id="id_txt" maxlength="2" style="width: 80px" onblur="doCal(this)"> input a number
<br />
<br />
<table id="id_tbl" border="1" cellpadding="0" cellspacing="0">
</table>
</body>
</html>
<script language="JavaScript">
<!--
function doCal(obj) {
var num = obj.value;
var tbl = document.getElementById("id_tbl");
if (document.body.all)
{
tbl.innerText = "";
}
else
{
tbl.innerHTML = "";
}
if (isNaN(num) || num.trim() == "")
{
return;
}
for (var i = 1; i <= num; i++)
{
var newRow = tbl.insertRow(tbl.rows.length);
for (var j = 1; j <= i; j++)
{
var newCell = document.createElement("td");
newCell.innerHTML = i + "*" + j + " = " + i * j;
newRow.appendChild(newCell);
}
for (j; j <= num; j++)
{
var newCell = document.createElement("td");
newCell.innerHTML = " ";
newRow.appendChild(newCell);
}
}
}
String.prototype.trim = function() {
return this.replace(/(^\s*)|(\s*$)/g, "");
};
//-->
</script>