当前位置: 移动技术网 > IT编程>开发语言>JavaScript > 九九乘法表,全js编写,放入table表格带入页面渲染出来

九九乘法表,全js编写,放入table表格带入页面渲染出来

2019年03月12日  | 移动技术网IT编程  | 我要评论

 1 <!doctype html>
 2 <html lang="en">
 3 
 4 <head>
 5     <meta charset="utf-8">
 6     <meta name="viewport" content="width=device-width, initial-scale=1.0">
 7     <meta http-equiv="x-ua-compatible" content="ie=edge">
 8     <title>九九乘法表</title>
 9 </head>
10 <body>
11     <input type="number" id="userinput">
12     <input type="button" id="quer" value="确认">
13     <table border="1"></table>
14     <script>
15         function off(num=9){//创建一个函数
16             for(let i=1;i<=num;i++){
17                 let tr=document.createelement("tr");//创建tr;
18                 for(let j=1;j<=i;j++){
19                     let td=document.createelement("td")//创建td
20                     td.innerhtml+=`${i}*${j}=${i*j}  `;//把i*j=ij的过程赋值给td里面
21                     tr.appendchild(td);//把td添加到tr里面
22                 }
23                 document.queryselector("table").appendchild(tr);//找到table把tr添加到table里面
24             }
25         }
26         quer.onclick=function(){//点击quer的时候里都为空值,在重新赋值;
27             document.queryselector("table").innerhtml="";
28             off(userinput.value-0);
29         } 
30     </script>
31 </body>
32 
33 </html>

 


 

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网