riddele_for_you,
<!DOCTYPE html>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
<style type="text/css">
</style>
</head>
<body>
<div class="matrix" oninput="createMatrix(5)"></div>
<div class="show"></div>
<script>
function print(a, e, b) {
a = a.reduce(function(a, b) {
return a + "<div>" + JSON.stringify(b) + "</div>";
}, e);
document.querySelector(".show").innerHTML = a + b;
}
function oms_mhwA(el) {
var matrix = document.querySelector(".matrix");
matrix.innerHTML = "";
for (var i = 0; i < el; i++) {
for (var k = 0; k < el; k++) {
matrix.innerHTML += '<input type="text" value="1">';
}
matrix.innerHTML += "<br>";
}
}
function createMatrix(el) {
var matrix = [], inp = document.querySelectorAll(".matrix input");
for (var i = 0; i < inp.length; i++) {
if (!(i % el)) {
matrix.push([]);
}
matrix[i / el | 0].push(+inp[i].value);
}
print(matrix, "", "");
return matrix;
}
oms_mhwA(5);
createMatrix(5);
// oms_zakra(createMatrix(5))
</script>
</body>
</html>
|