我有代码html js css作为
$('.list li:nth-child(4)').after('<li class="new-elem"></li>'); li.new-elem {width:336px; height:280px; background:#faa}<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>
现在如何插入脚本
<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>作为:
$('.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>');这是错误代码
谢谢
发布于 2015-02-25 06:38:48
使用这个
$('.list li').eq('4').after('<li class="new-elem">My script ads here</li>');添加像这样的url
$('.list li').eq('4').after("<li class="new-elem"><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></li>");而不是
$('.list li:nth-child(4)').after('<li class="new-elem">My script ads here</li>'); 发布于 2015-02-25 06:34:57
$(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>');
});https://stackoverflow.com/questions/28712500
复制相似问题