浏览代码

hw7 finish

serg155alternate 2 年之前
父节点
当前提交
c214c5e0a1
共有 2 个文件被更改,包括 21 次插入21 次删除
  1. 6 5
      HW7 DOM Base/script.js
  2. 15 16
      HW8 Functioms 2/script.js

+ 6 - 5
HW7 DOM Base/script.js

@@ -58,12 +58,13 @@ let td = document.querySelectorAll('td');
        item.style.backgroundColor = 'yellow'; 
        item.parentNode.style.backgroundColor = 'green';
       
-/*       if (td[i].cellIndex === e.target.cellIndex){
-        for (let i=0; i <0; i++ ){};
-           console.log(td[i])
-        
+       if (td[i].cellIndex === e.target.cellIndex){
+        for (let i = 0; i < td.length/10; i++ ){
+            console.log(td[i].cellIndex)
+        };
+           
           
-      }; */
+      }; 
        
     } 
 

+ 15 - 16
HW8 Functioms 2/script.js

@@ -181,24 +181,23 @@ let someTree = {
     },
 }
 
+let body= '';
 function htmlRecConstructor (obj) {   
-    
     let {tagName, children, attrs, text} = obj;
-    let body =`<${tagName}>`; 
-        if (typeof children ==="object"){
-          for (let tag of children){
-            // console.log(tag); 
-             let  {tagName, children, attrs, text} = tag;
-             body +=`<${tagName}>`; 
-             htmlRecConstructor(tag); 
-             body +=`${text}`;
-             body +=`<${tagName}>`;
-            }
-        } 
+    let atribute, value;
+    if (attrs){ 
+            atribute = Object.keys(attrs); 
+            value = Object.values(attrs);  
+    } else atribute = '';
+        body +=`<${tagName} ${atribute}=${value}>`;  
+        if (typeof children ==="object"){    
+        for (let tag of children){
+            htmlRecConstructor(tag);   
+            }  
+        } else body +=`${text}`;
     body +=`<${tagName}>`; 
-            
-    document.write(body);  
-    console.log(body);  
+    return body;
+      
 };  
 htmlRecConstructor(someTree);  
-//document.write(htmlRecConstructor(someTree));
+document.write(body);