开发者

jQuery while loop to generate list

Hi I am trying to get a list from 1-100 without typing 开发者_C百科in each line. I know it is a while loop but I've never had to use a while loop...thanks.

  <ul>
    <li>9.99</li>
    ...
    <li>9.01</li>
  </ul>

I kick myself in advance...


var $ul = $( '<ul>' );

for ( var i = 999; i > 900; i-- ) {
    $ul.append( '<li>' + ( i / 100 ).toFixed(2) + '</li>' );
}

Live demo: http://jsfiddle.net/2YpxG/2/


<ul></ul><script> 
var $ul = $("ul");
for(i = 99; i >= 1;i--){ 
  o = ''; 
  if (i < 10)  
       o = 0 ; 
  $ul.append('<li>9.'+o+i+'</li>'); 
}</script>

http://sandbox.phpcode.eu/g/b0514


Here's an example of a for loop:

http://jsfiddle.net/SgNDR/


var _ul = $('ul');
for(i=1;i<1000;i++){
    $('<li/>').html((i/100).toFixed(2)).prependTo(_ul);
}

Demo: http://jsfiddle.net/AlienWebguy/XPrmm/

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜