|
@@ -0,0 +1,212 @@
|
|
|
+<!DOCTYPE html>
|
|
|
+<html>
|
|
|
+<head>
|
|
|
+ <meta charset="utf-8">
|
|
|
+ <title></title>
|
|
|
+</head>
|
|
|
+<body>
|
|
|
+ <div id="container"></div>
|
|
|
+ <script>
|
|
|
+//----------3 persons --- different fields --- fields check
|
|
|
+ /*let a={
|
|
|
+ name:'John',
|
|
|
+ surname:'Johnson'
|
|
|
+ };
|
|
|
+
|
|
|
+ let b={
|
|
|
+ name:"Ivan",
|
|
|
+ surname:"Ivanov"
|
|
|
+ };
|
|
|
+
|
|
|
+ let c={
|
|
|
+ name:'Kevin',
|
|
|
+ surname:"McKalister"
|
|
|
+ };
|
|
|
+
|
|
|
+ a.sex='man';
|
|
|
+ a.age=17;
|
|
|
+ b.fathername='Jonson';
|
|
|
+ c.age=19;
|
|
|
+
|
|
|
+ let key =prompt('','');
|
|
|
+
|
|
|
+ if(key in a){
|
|
|
+ alert(a[key]);
|
|
|
+ }*/
|
|
|
+
|
|
|
+//----------array of persons
|
|
|
+/* let a={
|
|
|
+ name:'John',
|
|
|
+ surname:'Johnson'
|
|
|
+ };
|
|
|
+
|
|
|
+ let b={
|
|
|
+ name:"Ivan",
|
|
|
+ surname:"Ivanov"
|
|
|
+ };
|
|
|
+
|
|
|
+ let c={
|
|
|
+ name:'Kevin',
|
|
|
+ surname:"McKalister"
|
|
|
+ };
|
|
|
+
|
|
|
+ let persons=[a,b,c];
|
|
|
+
|
|
|
+ persons.push({name:"Frank", surname:'Lampard'});
|
|
|
+
|
|
|
+ //loop of persons
|
|
|
+ for(let item of persons){
|
|
|
+ console.log(item);
|
|
|
+ }
|
|
|
+
|
|
|
+ //loop of name and surname
|
|
|
+ for(let item of persons){
|
|
|
+ console.log(item.name+" "+item.surname);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //loop of loop of values
|
|
|
+ for(let item of persons){
|
|
|
+ for(let name of Object.values(item)){
|
|
|
+ console.log(name);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //fullName
|
|
|
+ for(let item of persons){
|
|
|
+ item.fullName=item.name+" "+item.surname;
|
|
|
+ console.log(item.fullName);
|
|
|
+ }
|
|
|
+ console.log(persons);
|
|
|
+
|
|
|
+ //serialize
|
|
|
+ let json=JSON.stringify(persons,null,2);
|
|
|
+ console.log(json);
|
|
|
+
|
|
|
+ //deserialize
|
|
|
+ let d=JSON.parse(json)[0];
|
|
|
+ console.log(d);
|
|
|
+ persons.push(d);
|
|
|
+ console.log(persons);*/
|
|
|
+
|
|
|
+//----------HTML
|
|
|
+ /*let str = "<table border='1'><tr><td>Имя</td><td>Фамилия</td></tr>";
|
|
|
+ for (let i=0;i<persons.length;i++){
|
|
|
+
|
|
|
+ let g=persons[i];
|
|
|
+ str += `<tr><td>${g.name}</td><td>${g.surname}</td></tr>`;
|
|
|
+ }
|
|
|
+ str += "</table>";
|
|
|
+ document.write(str);*/
|
|
|
+
|
|
|
+//----------HTML optional fields --- HTML tr color
|
|
|
+ /*
|
|
|
+ let str = "<table border='1'>";
|
|
|
+ for (let i=0;i<persons.length;i++){
|
|
|
+
|
|
|
+ let g=persons[i];
|
|
|
+ if(i%2){
|
|
|
+ str+="<tr bgcolor='yellow'>";
|
|
|
+ }else{
|
|
|
+ str+='<tr>';
|
|
|
+ }
|
|
|
+ for(let item in g){
|
|
|
+ if(item){
|
|
|
+ str+=`<td>${item}: ${g[item]}</td>`;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ str+='</tr>';
|
|
|
+ }
|
|
|
+ str += "</table>";
|
|
|
+ document.write(str);*/
|
|
|
+
|
|
|
+//---------HTML th optional
|
|
|
+ /*persons[2].age=19;
|
|
|
+ persons[3].age=27;
|
|
|
+ persons[3].sex='man';
|
|
|
+ let keys=[];
|
|
|
+ for(let item of persons){
|
|
|
+ for(let i of Object.keys(item)){
|
|
|
+ if(!keys.includes(i)){
|
|
|
+ keys.push(i);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ console.log(keys);
|
|
|
+ let str = "<table border='1'><tr>";
|
|
|
+ for(let i of keys){
|
|
|
+ str+=`<th>${i}</th>`;
|
|
|
+ }
|
|
|
+ str+='</tr>';
|
|
|
+
|
|
|
+ for(let item of persons){
|
|
|
+ str+='<tr>';
|
|
|
+ for(let it in item){
|
|
|
+ for(let i=0;i<keys.length;i++){
|
|
|
+ if(keys[i]==it){
|
|
|
+ str+=`<td bgcolor='yellow'>${item[it]}</td>`;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ str+='</tr>';
|
|
|
+ }
|
|
|
+ document.write(str);*/
|
|
|
+
|
|
|
+//----------Blue belt
|
|
|
+ var someTree = {
|
|
|
+ tagName: "table",
|
|
|
+ subTags: [
|
|
|
+ {
|
|
|
+ tagName: "tr",
|
|
|
+ subTags: [
|
|
|
+ {
|
|
|
+ tagName: "td",
|
|
|
+ text: "some text",
|
|
|
+ },
|
|
|
+ {
|
|
|
+ tagName: "td",
|
|
|
+ text: "some text 2",
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ attrs: {
|
|
|
+ border: 1,
|
|
|
+ },
|
|
|
+ }
|
|
|
+
|
|
|
+ container.innerHTML=createHTML(someTree);
|
|
|
+
|
|
|
+ function createHTML(obj){
|
|
|
+
|
|
|
+ for(let i in obj){
|
|
|
+ let tag=document.createElement(obj.tagName);
|
|
|
+ if(i==subTags){
|
|
|
+ for(let item of subTags){
|
|
|
+ let tag2=document.createElement(item[0].tagName);
|
|
|
+ tag.append()
|
|
|
+
|
|
|
+ if(item[0].subTags){
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ tag.append()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ </script>
|
|
|
+
|
|
|
+</body>
|
|
|
+</html>
|