我有一篇文章,其中包含一堆paragraphs
。在第三个paragraph
之后,我需要添加一个广告位。之后,每五段添加一个广告位。我试图用这些HTML tags
来模仿我想要完成的事情。仅为第三个div添加元素,之后每五个div
for(var i = 0; i<tasks.length; i++){
if(tasks[i].tagName == 'DIV'){
if (i && (i % 5 == 0)) {
//Logic to add elements go here
}
}
}
<div>1</div>
<div>2</div>
<div>3(Here is where the element will be added)</div>
<div>4</div>
<div>5</div>
<div>6</div>
<div>7</div>
<div>8(Here is where the element will be added)</div>
'(ⅰ%5 == 2)'将返回如果为真i == 2,7,12,17 ... – James