rendered paste body<html>
<head>
<script>
var ClonerClass = function()
{
this.Data = new Array();
this.CurrentObject = new Object();
this.Attributes = [ 'id' ];
this.cloneNode = function( Data, Node, TargetNode )
{
this.Data = Data;
var clonedNode = Node.cloneNode( true );
TargetNode.appendChild( clonedNode );
this.replaceVars( clonedNode );
return clonedNode;
}
this.replaceVars = function( Node )
{
if( !Node.innerHTML )
{
var html = Node.nodeValue;
for( key in this.Data )
{
html = html.replace( '%' + key + '%', this.Data[key] );
}
Node.nodeValue = html;
}
if( Node.attributes && Node.attributes.length )
{
for( var i=0; i<this.Attributes.length; i++ )
{
if( Node.attributes[this.Attributes[i]] )
var html = Node.attributes[this.Attributes[i]].nodeValue;
for( key in this.Data )
{
html = html.replace( '%' + key + '%', this.Data[key] );
}
Node.attributes[this.Attributes[i]].nodeValue = html;
}
}
if( Node.childNodes && Node.childNodes.length )
{
for( var i=0; i<Node.childNodes.length; i++ )
{
this.replaceVars( Node.childNodes[i] );
}
}
}
}
var Cloner = new ClonerClass();
function addItem( data )
{
var clonedNode = Cloner.cloneNode( data, document.getElementById( 'exampleItem' ), document.getElementById( 'exampleItem' ).parentNode );
clonedNode.id = 'item_' + data['index'];
clonedNode.style.display = '';
}
function fillItems()
{
var data = { 'index': '454000', 'name': 'Пазл', 'count': 2 };
addItem( data );
var data = { 'index': '800000', 'name': 'Булка', 'count': 5 };
addItem( data );
}
</script>
</head>
<body onLoad="fillItems();">
<div>Индекс</div>
<div>Наименование</div>
<div>Количество</div>
<div id="exampleItem" style="display: none">
<div>%index%</div>
<div>%name%</div>
<div>%count%</div>
</div>
</body>
</html>