JS动态生成内容
<html>
<head>
<title></title>
</head>
<body>
<input name= "bbb" id= "bbb" type= "button" value= "运行" onclick= "test()">
<h3>点击“运行”按钮后,将动态生成如下内容:</h3>
<div id = "ddd"></div>
</body>
</html>
<script type= "text/javascript">
var _timeout;
function test(){
if(_timeout!=undefined){
clearTimeout(_timeout);
}
appendA();
_timeout = window.setTimeout(test,50);
}
function appendA(){
var myElement = document.createElement('<b></b>');
myElement.innerText= "a";
document.getElementById('ddd').appendChild(myElement);
}
</script>
<head>
<title></title>
</head>
<body>
<input name= "bbb" id= "bbb" type= "button" value= "运行" onclick= "test()">
<h3>点击“运行”按钮后,将动态生成如下内容:</h3>
<div id = "ddd"></div>
</body>
</html>
<script type= "text/javascript">
var _timeout;
function test(){
if(_timeout!=undefined){
clearTimeout(_timeout);
}
appendA();
_timeout = window.setTimeout(test,50);
}
function appendA(){
var myElement = document.createElement('<b></b>');
myElement.innerText= "a";
document.getElementById('ddd').appendChild(myElement);
}
</script>
本文转自 leizhimin 51CTO博客,原文链接:http://blog.51cto.com/lavasoft/493686,如需转载请自行联系原作者