简体   繁体   中英

jquery each fadein input boxes

I would like to fade in an input box for the number given, If I had 5 as the number I would like to fade in 5 input boxes. can someone help?

$('.submit').click(function(){
     var num = $('#num').val();

$.each(function() {
         $('.box').fadeIn('fast').html('<input type="text">');//I need five input boxes
      });
});

Your $.each() call is incorrect. Try simple for loop:

$('.submit').click(function(){
    var num = parseInt($('#num').val());
    var html = '';

    for (; num > 0; num--) {
        html += '<input type="text">';
    }

    $('.box').html(html).fadeIn('fast');
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM