论坛首页 入门技术论坛

select通用实时排序

浏览 1225 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2013-07-26  
function generalSelectSort(selector_id,value,text) {
        var first = '';
        if ($("#"+selector_id).children("option").length === 0) {
            $("#operation_selector").append('<option value="' + value + '">' + text + '</option>');
            first = text;
        }
        var appended = 0;
        $("#"+selector_id).children("option").each(function(){
            if($(this).text().toLowerCase() > text.toLowerCase() && appended === 0) {
                $(this).before('<option value="' + value + '">' + text + '</option>');
                appended = 1;
            }
        });
        // the last one
        if(appended === 0 && first !== text) {
            $("#"+selector_id).append('<option value="' + value + '">' + text + '</option>');
        }
    }

 

论坛首页 入门技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics