JS动态创建元素

1、JS动态创建iframe

<script language="JavaScript">
var ifm = document.createElement("iframe");
ifm.id="ifm";
ifm.width="100%";
ifm.frameborder=1;
ifm.src="http://www.cnfol.com";
document.body.appendChild(ifm);
</script>

 2、JS动态创建script

<div id="board" style="display:none;"></div>
<script type="text/javascript">
var board = document.getElementById("board");
var newscript = document.createElement("script");
newscript.type="text/javascript";
newscript.src=“XXX.js”;
newscript.id = 'test';
var object = board.appendChild(newscript);
</script>

 

你可能感兴趣的:(JavaScript)