# JJU_干干
要点:
将字符串插入到html中id指定地方
document.getElementById("id名").innerHTML = "字符串";
代码:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>九九乘法表</title> </head> <body> <div id="table"></div> <script type="text/javascript"> var str = "<table>"; for(var i=1;i<=9;i++){ str += "<tr>"; for(var j=1;j<=i;j++){ str += "<td>"; str += j+"*"+i+"="+(i*j) str += "</td>"; } str += "</tr>"; } str += "</table>"; // 将字符串插入到html中id为table的地方 document.getElementById("table").innerHTML = str; </script> </body> </html>
运行结果: