我正在玩javascript嵌入式,我从我的服务器获取的代码javascript,代码javascript将生成横幅。
我服务器的javascript示例是:
<script type='text/javascript'>
<!--//<![CDATA[
var m3_u = (location.protocol=='https:'?'https://203.130.226.231/advediax/www/delivery/ajs.php':'http://203.130.226.231/advediax/www/delivery/ajs.php');
var m3_r = Math.floor(Math.random()*99999999999);
if (!document.MAX_used) document.MAX_used = ',';
document.write ("<scr"+"ipt type='text/javascript' src='"+m3_u);
document.write ("?zoneid=1");
document.write ('&cb=' + m3_r);
if (document.MAX_used != ',') document.write ("&exclude=" + document.MAX_used);
document.write (document.charset ? '&charset='+document.charset : (document.characterSet ? '&charset='+document.characterSet : ''));
document.write ("&loc=" + escape(window.location));
if (document.referrer) document.write ("&referer=" + escape(document.referrer));
if (document.context) document.write ("&context=" + escape(document.context));
if (document.mmm_fo) document.write ("&mmm_fo=1");
document.write ("'><\/scr"+"ipt>");
//]]>-->
</script>
在下面有标签div id banner。
<div id="banner">For banner</div>
<script>
// Possible to move script from my server into tag banner?
// If yes, how to do it?
</script>
条件html现在大致如下:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<script type='text/javascript'>
<!--//<![CDATA[
var m3_u = (location.protocol=='https:'?'https://203.130.226.231/advediax/www/delivery/ajs.php':'http://203.130.226.231/advediax/www/delivery/ajs.php');
var m3_r = Math.floor(Math.random()*99999999999);
if (!document.MAX_used) document.MAX_used = ',';
document.write ("<scr"+"ipt type='text/javascript' src='"+m3_u);
document.write ("?zoneid=1");
document.write ('&cb=' + m3_r);
if (document.MAX_used != ',') document.write ("&exclude=" + document.MAX_used);
document.write (document.charset ? '&charset='+document.charset : (document.characterSet ? '&charset='+document.characterSet : ''));
document.write ("&loc=" + escape(window.location));
if (document.referrer) document.write ("&referer=" + escape(document.referrer));
if (document.context) document.write ("&context=" + escape(document.context));
if (document.mmm_fo) document.write ("&mmm_fo=1");
document.write ("'><\/scr"+"ipt>");
//]]>-->
</script>
<div id="banner"> </div>
</body>
</html>
我想如下:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div id="banner">
<script type='text/javascript'>
<!--//<![CDATA[
var m3_u = (location.protocol=='https:'?'https://203.130.226.231/advediax/www/delivery/ajs.php':'http://203.130.226.231/advediax/www/delivery/ajs.php');
var m3_r = Math.floor(Math.random()*99999999999);
if (!document.MAX_used) document.MAX_used = ',';
document.write ("<scr"+"ipt type='text/javascript' src='"+m3_u);
document.write ("?zoneid=1");
document.write ('&cb=' + m3_r);
if (document.MAX_used != ',') document.write ("&exclude=" + document.MAX_used);
document.write (document.charset ? '&charset='+document.charset : (document.characterSet ? '&charset='+document.characterSet : ''));
document.write ("&loc=" + escape(window.location));
if (document.referrer) document.write ("&referer=" + escape(document.referrer));
if (document.context) document.write ("&context=" + escape(document.context));
if (document.mmm_fo) document.write ("&mmm_fo=1");
document.write ("'><\/scr"+"ipt>");
//]]>-->
</script>
</div>
</body>
</html>
在问题中我无法将我的脚本插入并粘贴到div id banner,因为其他人拥有的内容。所以我只是拥有主要的javascript。 我的问题,可以将javascript从我的服务器移动到tag div id banner吗?
由于
答案 0 :(得分:1)
document.getElementById('banner').innerHTML = 'script string (including tags)';
答案 1 :(得分:-1)
如果您使用jQuery,则可以使用:
jQuery.getElementByID("banner").text(*Insert your code here*);