我有代码html js css as
$('.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>
as:
$('.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>');
这是错误代码
由于
答案 0 :(得分:0)
$(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 :(得分:0)
使用此
$('.list li').eq('4').after('<li class="new-elem">My script ads here</li>');
像这样添加网址
$('.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>');