All pastes #931483 Raw Edit

new_with_div

public text v1 · immutable
·published 2008-03-07 06:45 UTC
rendered paste body
<html>
<head>
	<script>
		var ClonerClass = function()
		{
			this.Data = new Array();
			this.CurrentObject = new Object();
			this.cloneNode = function( Data, Node, TargetNode )
			{
				this.Data = Data;
				var clonedNode = Node.cloneNode( true );
				TargetNode.appendChild( clonedNode );
				this.runScript( clonedNode );
				return clonedNode;
			}

			this.runScript = function( Node )
			{
				if( !Node.getElementsByTagName ) return;
				var nodes = Node.getElementsByTagName( 'script' );
				for( var i=0; i<nodes.length; i++ )
				{
					this.CurrentObject = nodes[i].parentNode;
					eval( nodes[i].innerHTML );
				}
				for( var i=0; i<Node.childNodes.length; i++ )
				{
					if( Node.childNodes[i].nodeName != 'script' )
					{
						this.runScript( Node.childNodes[i] );
					}
				}

			}
			this.getObject = function()
			{
				return this.CurrentObject;
			}

			this.getData = function()
			{
				return this.Data;
			}
		}

		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><script>Cloner.getObject().innerHTML = Cloner.getData()['index'];</script></div>
		<div><script>Cloner.getObject().innerHTML = Cloner.getData()['name'];</script></div>
		<div><script>Cloner.getObject().innerHTML = Cloner.getData()['count'];</script></div>
	</div>
</body>
</html>