动态生成div子标签

<html>
	<head>
		<script>
			function add_div(){
				var div = document.createElement('div');
				div.className='ds1';
				var tex = document.createTextNode('hello');
				div.appendChild(tex);
				var done = document.getElementById('done');
				done.appendChild(div);
			}
		</script>
		<style>
			.ds1{
				height:80;
				width:80;
				background:red;
			}
			.dib{
				height:600;
				width:600;
				background:yellow;
			}
		</style>
	</head>
	<body style="font-size:12pt;">
		<a href="javascript:;" onclick="add_div();">create a new div</a>
		<div id="done" class="dib"><div>
	</body>
</html>

你可能感兴趣的:(html)