Javascript-форум (https://javascript.ru/forum/)
-   Общие вопросы Javascript (https://javascript.ru/forum/misc/)
-   -   Работа "Таблица умножения" на javaScript (https://javascript.ru/forum/misc/38075-rabota-tablica-umnozheniya-na-javascript.html)

pavel23 17.05.2013 22:00

Работа "Таблица умножения" на 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>

danik.js 18.05.2013 03:46

<!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>

noiner 29.10.2014 23:35

создаешь функцию:
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 + "&times;" + i + "=" + (i * j) + "</td>")}
document.write("</tr>")
}
document.write("</table>")
}

потом вызываешь ее в html документе:
<script type = "text/javascript">
table()
</script>

ruslan_mart 30.10.2014 05:11

noiner, а теперь проверь, что получится.


Часовой пояс GMT +3, время: 02:34.