Closed. This question needs details or clarity。它当前不接受答案。
                        
                    
                
            
        
            
        
                
                    
                
            
                
                    想改善这个问题吗?添加详细信息并通过editing this post阐明问题。
                
                    5年前关闭。
            
        

    


  如何使以下JavaScript代码正常工作并生成列表
  ID为“ myDivId”的元素内的名称和年龄的划分:


<div id="myDivId">No results yet</div>
<script>
new PersonPrinter("myDivId",[{"name":"Joe","age":"23"}
{"name":"Sam","age":"31"}]).render();
</script>`

最佳答案

In the PersonPrinter render function you need to update the div

PersonPrinter.prototype.render = function(id,data) {
var elem = document.elementById(id);
for (var i =0;i <data.length;i++) {

var d = dcoument.createElement('div');
d.appendChild(document.createTextNode('Name'+data.name +'  Age:'+data.age');
elem.appendChild(d);`enter code here`
}
}

10-04 13:17