$.each() index start number in jQuery

前端 未结 8 1958
慢半拍i
慢半拍i 2021-01-05 02:28

How do I start jQuery $.each() index from 1 instead of 0?

I am using .each function to populate select box. So here I want to populate options in the se

8条回答
  •  庸人自扰
    2021-01-05 02:58

    Seeing the clarification points in the comments below, jQuery.each or some variation thereof isn't the right tool at all. Use a for loop, and add 1 to the index to output the value of the .

    Use .prepend to insert an option as the first child of a select:

    for (var i = 0; i < 10; i++) {
        $('select').prepend('');
    }
    

提交回复
热议问题