Таблицы через JS
Привет, подмогните пожалуйста. Есть обьект и прототип. Нужно запихнуть это все в таблицу через JS, таблицу вроде получилось создать, подскажите как дальше быть?
function Stud(name, surname, group, age){ this.name=name; this.surname=surname; this.group=group; this.age=age; } var students=[ new Stud('vasya','pupko','php','22'), new Stud('kolya','zubko','java','20'), new Stud('tolya','tupko','front','25'), new Stud('vitalya','rybko','python','19'), new Stud('olya','lyashko','c++','28') ]; var table = ""; var rows = 4; var cols = 5; for (var r = 0; r < rows; r++) { table = table + "<tr>"; for (var c = 1; c <= cols; c++) { table = table + "<td>" + c + "</td>"; } table = table + "</tr>"; } document.write("<table border=2>" + table + "</table>"); |
Fireyon,
<!DOCTYPE html> <html> <head> <title>Untitled</title> <meta charset="utf-8"> </head> <body> <script> function Stud(name, surname, group, age){ this.name=name; this.surname=surname; this.group=group; this.age=age; } var students=[ new Stud('vasya','pupko','php','22'), new Stud('kolya','zubko','java','20'), new Stud('tolya','tupko','front','25'), new Stud('vitalya','rybko','python','19'), new Stud('olya','lyashko','c++','28') ]; function tbl(data) { return "<table border=2>" + data.reduce(function(tb, el) { return tb + "<tr><td>" + Object.values(el).join("</td><td>") + "</td></tr>" }, "") + "</table>" }; document.body.insertAdjacentHTML('beforeEnd', tbl(students)); </script> </body> </html> |
Часовой пояс GMT +3, время: 13:47. |