开发者

loop javascript with css content

i need in my code to repeat ten times this content, then i think that is possible in a loop like a for or while, but i tried and i can't

<li>
    <img style="float: left;" src="img/gaja.jpg" alt="Angry face" />
    <div style="width: 100px; height: 20px; float:left; margin-left: 5px; font: bold 12px aria开发者_JS百科l;">IceMan</div>
    <div style="width: 150px; height: 20px; float:left; margin-left:5px;">Web Designer / FullTime</div>
</li>

any help?

thanks


var li = $('li');
for(var i = 0; i < 10; i++) {
    li.clone().appendTo(li.parent());
}


Since the jQuery was not specified in the inital question I am going to assume it is not being used.

The pure JavaScript way would be like so:

var ul = document.getElementsByTagName("ul")[0];
var li = ul.getElementsByTagName("li")[0];
for(var i=1;i<10;i++){
    ul.appendChild(li.cloneNode(true));
}

Code example on jsfiddle.


for (var i = 0; i < 10; i++)
{
    document.write('<li>');
    document.write('<img style="float: left;" src="img/gaja.jpg" alt="Angry face" />');
    document.write('<div style="width: 100px; height: 20px; float:left; margin-left: 5px; font: bold 12px arial;">IceMan</div>');
    document.write('<div style="width: 150px; height: 20px; float:left; margin-left:5px;">Web Designer / FullTime</div>');
    document.write('</li>');
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜