Работа "Таблица умножения" на javaScript
Всем здравствуйте!!!
Помогите пожалуйста мне нужно сделать таблицу умножения в javaScript написать. У меня не получается сделать таблицу как на обложке в тетрадке чтобы она была разделена на столбики. Нам сказали что через DIV Как и куда его ставить? <html> <body> <script language="javaScript"> for (i=1; i<10; i++) for (j=1; j<10; j++) document.write("<p>"+i+"*"+j+" = "+(i*j)+"</p>"); </script> </body> </html> |
<!DOCTYPE html> <body> <script> var table, row, cell, i, j; table = document.createElement('table'); table.style.textAlign = 'right'; table.style.fontFamily = 'monospace'; for (i=1; i<10; i++) { row = document.createElement('tr'); for (j=1; j<10; j++) { cell = document.createElement(i == 1 || j == 1 ? 'th' : 'td'); cell.appendChild(document.createTextNode(i*j)); cell.style.padding = '4px'; cell.style.width = 100 / 9 + '%'; row.appendChild(cell); } table.appendChild(row); } document.body.appendChild(table); </script> </body> |
создаешь функцию:
function table() { document.write("<table border= \" 1 \" cellspacing= \" 0 \" cellpadding= \"2 \"align= \"center \" >") for (var i = 1; i <= 10; i++) {document.write("<tr>"); for (var j = 1; j < 10; j++) {document.write("<td>" + j + "×" + i + "=" + (i * j) + "</td>")} document.write("</tr>") } document.write("</table>") } потом вызываешь ее в html документе: <script type = "text/javascript"> table() </script> |
noiner, а теперь проверь, что получится.
|
Часовой пояс GMT +3, время: 17:54. |