动态向DIV里写入JS 解决第3方广告加载问题 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 不理解你想要什么。innerHTML?? 在页面最后面加载 document.getElementById("id").innerHTML=... <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>无标题文档</title> </head> <body> <form method="POST" name="f1"> 姓名:<input type="text" name="xm" ><input type="button" value="确定" name="B1" onclick=hy()> </form> <SCRIPT LANGUAGE="JavaScript"> function hy(){ var temp=document.getElementById("content").innerHTML; document.getElementById("content").innerHTML=temp+"欢迎"+document.f1.xm.value+"!<br>"; } </SCRIPT> <div id="content"> </div> </body> </html> document.getElementById("id").innerHTML不能写入JavaScript啊 1、不能用innerHTML向div中写入"<script></script>"。解决办法:(1)在添加一个其他的html标记:obj.innerHTML="<br><script>"+scriptStr+"</script>";(2)使用如下脚本:var obj=document.getElementById("test");var str="alert('xx');var a=100;document.write(a);document.write('aaaa')";var oScript=document.createElement("script");oScript.text=str;obj.appendChild(oScript);2、无法执行脚本中的document.write脚本,或者说执行时把页面内容清空了。原因:document.write只有在加载时执行才不会清空页面内容,其他时间执行则会清空页面内容。解决办法:既然document.write的目的就是在指定的div中写入内容,把脚本中的document.write替换为innerHTML不久ok了吗?经过多次测试终于ok了。<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh-CN" lang="zh-CN"> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /></head><body><div id="test"></div><input type="button" onclick="test()" /><script type="text/javascript">function addScript(id,str){ window.execScript((str+";").replace(/<\/?script[^\)]*>/ig,"").replace(/document.write\((.*?)\)[\s;]/ig,function(){ return ("document.getElementById('"+id+"').innerText+="+arguments[1]+";"); }));}window.onload=function(){var id="test";var str="alert('xx');\nvar a=100;document.write('(xxx)');document.write('aaaa')\n";addScript(id,str)};</script></body></html> function createScript(url) { var element = document.createElement("script" ); element.type = "text/javascript" ; element.src = url; document.getElementsByTagName("head" )[0].appendChild(element); } 广告一般都是这样加载的:<div><script type="text/javascript" src="ad url"></script></div> 如何用Jquery循环td 晕了 addEventListener怎么往里面传参?? 关于ec:table的问题 javascript向div的innerHTML赋值丢失<style> 开发JS一般用什么工具 跨浏览器JS代码如何编写有没这方面的资料 不通过getElementByTagName如何实现文件中所有DIV隐藏? 双击一行如何得到这一行的第一列和第三列的值? 找到弹出窗口的焦点? KindEditor自定义弹出框架页面,怎样得到返回值 jsp上显示图片 firebug+F8
innerHTML??
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head> <body>
<form method="POST" name="f1">
姓名:<input type="text" name="xm" ><input type="button" value="确定" name="B1" onclick=hy()>
</form>
<SCRIPT LANGUAGE="JavaScript">
function hy(){
var temp=document.getElementById("content").innerHTML;
document.getElementById("content").innerHTML=temp+"欢迎"+document.f1.xm.value+"!<br>";
}
</SCRIPT>
<div id="content">
</div>
</body>
</html>
解决办法:
(1)在添加一个其他的html标记:obj.innerHTML="<br><script>"+scriptStr+"</script>";
(2)使用如下脚本:
var obj=document.getElementById("test");
var str="alert('xx');var a=100;document.write(a);document.write('aaaa')";
var oScript=document.createElement("script");
oScript.text=str;
obj.appendChild(oScript);
2、无法执行脚本中的document.write脚本,或者说执行时把页面内容清空了。
原因:document.write只有在加载时执行才不会清空页面内容,其他时间执行则会清空页面内容。解决办法:既然document.write的目的就是在指定的div中写入内容,把脚本中的document.write替换为innerHTML不久ok了吗?经过多次测试终于ok了。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh-CN" lang="zh-CN">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
</head>
<body>
<div id="test"></div>
<input type="button" onclick="test()" />
<script type="text/javascript">
function addScript(id,str){
window.execScript((str+";").replace(/<\/?script[^\)]*>/ig,"").replace(/document.write\((.*?)\)[\s;]/ig,function(){
return ("document.getElementById('"+id+"').innerText+="+arguments[1]+";");
}));
}window.onload=function(){
var id="test";
var str="alert('xx');\nvar a=100;document.write('(xxx)');document.write('aaaa')\n";
addScript(id,str)
};
</script>
</body>
</html>
var element = document.createElement("script" );
element.type = "text/javascript" ;
element.src = url;
document.getElementsByTagName("head" )[0].appendChild(element);
}
<script type="text/javascript" src="ad url"></script>
</div>