ни как не понимаю почему то такая штука не работает,
function addComponent(_obj, _arr)
{
for(var k in _arr)
{
if(typeof _arr[k].tagname == 'string')
{
var tag = _arr[k].tagname;
var Component = document.createElement(tag);
alert(typeof Component);
if(typeof _arr[k].attributes == 'object')
{
var attributes = _arr[k].attributes;
for(var d in attributes)
{
if(typeof attributes[d] == 'string')
{
Component[d] = attributes[d];
}
}
}
var domComponent = _obj.appendChild(Component);
if(typeof _arr[k].Child == 'object')
{
addComponent(domComponent, _arr[k].Child);
}
}
}
}
function init()
{
var mx = [{
tagname:'table',
attributes:{
width:'100%',
height:'600',
bgcolor:'#0000CC'
},
Child:[{
tagname:'tr',
Child:[{
tagname:'td',
innerHTML:'text text text text text text '
},{
tagname:'td',
innerHTML:'text text text text text text '
},{
tagname:'td',
innerHTML:'text text text text text text '
},{
tagname:'td',
innerHTML:'text text text text text text '
}]
},{
tagname:'tr',
Child:[{
tagname:'td',
innerHTML:'text text text text text text '
},{
tagname:'td',
innerHTML:'text text text text text text '
},{
tagname:'td',
innerHTML:'text text text text text text '
},{
tagname:'td',
innerHTML:'text text text text text text '
}]
}]
}];
addComponent(document.body, mx);
}