首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >脚本加载脚本广告

脚本加载脚本广告
EN

Stack Overflow用户
提问于 2015-02-25 06:20:46
回答 2查看 51关注 0票数 0

我有代码html js css作为

代码语言:javascript
复制
$('.list li:nth-child(4)').after('<li class="new-elem"></li>'); 
代码语言:javascript
复制
li.new-elem {width:336px; height:280px; background:#faa}
代码语言:javascript
复制
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<article class="list">
  <li>Thi is list post 01</li>
  <li>Thi is list post 01</li>
  <li>Thi is list post 01</li>
  <li>Thi is list post 01</li>
  <li>Thi is list post 01</li>
</article>

现在如何插入脚本

代码语言:javascript
复制
<script type="text/javascript">document.write("<iframe src='http://www.myadscode.com/ads/banneriframe.php?pchsh=xxxxxxxxxxxxxxxxxxx&t=336x280&cb=" + (Math.floor(Math.random()*99999) + new Date().getTime()) + "' style='width:336px;height:280px;' frameborder='0' scrolling='no'></iframe>");</script>

作为:

代码语言:javascript
复制
$('.list li:nth-child(4)').after('<li class="new-elem"><script type="text/javascript">document.write("<iframe src='http://www.myadscode.com/ads/banneriframe.php?pchsh=xxxxxxxxxxxxxxxxxxx&t=336x280&cb=" + (Math.floor(Math.random()*99999) + new Date().getTime()) + "' style='width:336px;height:280px;' frameborder='0' scrolling='no'></iframe>");</script></li>');

这是错误代码

谢谢

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-02-25 06:38:48

使用这个

代码语言:javascript
复制
 $('.list li').eq('4').after('<li class="new-elem">My script ads here</li>');

添加像这样的url

代码语言:javascript
复制
$('.list li').eq('4').after("<li class="new-elem"><iframe src='http://www.myadscode.com/ads/banneriframe.php?pchsh=xxxxxxxxxxxxxxxxxxx&t=3‌​36x280&cb=" + (Math.floor(Math.random()*99999) + new Date().getTime()) + "' style='width:336px;height:280px;' frameborder='0' scrolling='no'></iframe></li>");

而不是

代码语言:javascript
复制
$('.list li:nth-child(4)').after('<li class="new-elem">My script ads here</li>'); 
票数 0
EN

Stack Overflow用户

发布于 2015-02-25 06:34:57

代码语言:javascript
复制
 $(function() { 
     var l = $('.list li').length-1;
        $('.list li').eq(l).after('<li class="new-elem">My script ads here</li>');
     });
     <!-- ========= Or ======= -->
      $(function() { 
         $('.list li').eq('4').after('<li class="new-elem">My script ads here</li>');
 });
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28712500

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档