我试图只使用一次函数,而不是为我需要转换为选择列表的每个 UL LI 块编写它。我的工作代码在http://jsfiddle.net/qqzB5/
我试过了,但它会遍历所有 li,而不仅仅是特定部分中的那个:
$('.filterSection').each(function(){
        $('<select class="locationFilterSelect" />').appendTo(this);
        //Create Default option "Select One"
        $("<option />", {
           "selected": "selected",
           "value"   : "",
           "text"    : "Select One"
        }).appendTo('select', this);
        // Populate dropdown with menu items
        $('li', this).each(function() {
             var el = $(this);
             $("<option />", {
                 "text"    : el.text()
             }).appendTo('select', this);
        });
    });