JavaScript-DOM(九九乘法表)——两种算法
Posted 勇敢*牛牛
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JavaScript-DOM(九九乘法表)——两种算法相关的知识,希望对你有一定的参考价值。
通过ul中的li来做九九乘法表
代码描述:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>javascript-DOM(九九乘法表)</title>
</head>
<body>
<ul id="01">
</ul>
<script>
// var data = "";
/* for (var i = 0; i <= 9; i++)
data += "<li>" + "这是第" + (i + 1) + "个数字" + "</li>";
*/
var data = "";
for (var i = 1; i <= 9; i++)
data += "<li>";
for (var j = 1; j <= i; j++)
data += j + "*" + i + "=" + (i * j) + "  ";
data += "</li>";
var x = document.getElementById("01");
x.innerHTML = data;
</script>
</body>
</html>
通过换行标签<br />
来实现9*9乘法表
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JavaScript-DOM(九九乘法表)</title>
</head>
<body>
<div id="02">
</div>
<script>
var data = "";
for (var i = 1; i <= 9; i++)
for (var j = 1; j <= i; j++)
data += j + "*" + i + "=" + (i * j) + "  ";
data += "<br/>";
var x = document.getElementById("02");
x.innerHTML = data;
</script>
</body>
</html>
以上是关于JavaScript-DOM(九九乘法表)——两种算法的主要内容,如果未能解决你的问题,请参考以下文章