<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script>
function fun1(){
//获得input控件
var inp = document.getElementById("input1");
//获得此控件的value值
var inputValue = inp.value;
var ddd = document.getElementById("div1");
if(inputValue>=1&&inputValue<=9){
ddd.innerHTML = "成功";
//定义一个内容的变量,初值是空字符串
var content = "<table>";
for(var i=1;i<=inputValue;i++){
content += "<tr>";
for(var j=1;j<=i;j++){
//循环体连接字符串
content += "<td bgcolor='pink'>"+j+"*"+i+"="+(j*i)+" </td>";
}
content +="</tr>";
}
content += "</table>";
console.log(content);
ddd.innerHTML = content;
}else{
ddd.innerHTML = "失败";
}
}
</script>
</head>
<body>
<input type="text" id="input1" />
<input type="button" value="生成" οnclick="fun1()"/>
<div id="div1" ></div>
</body>
</html>
九九乘法表
最新推荐文章于 2024-11-14 00:00:11 发布