パッケージ)のselectタグのjs操作

1508 ワード

function BindSelect(id,dataList,fieldtext,fieldValue) {
//        ,fieldtext          ,fieldValue      value  
    var select = $("#" + id)[0];  
    for (var i = 0; i < dataList.length; i++) {
        select.options.add(new Option(eval("dataList[" + i + "]." + fieldtext), eval("dataList[" + i + "]." + fieldValue)));
    }
}
function BindSelectOptions(id, OptionList) {
    var select = $("#" + id)[0];
    for (var i = 0; i < OptionList.length; i++) {
        select.options.add(new Option(OptionList[i].Text, OptionList[i].Value));
    }
}
function ClearAllItems(id) {//       
    var select = $("#" + id)[0];
    select.options.length = 0;
}
function AddOneItem(id, text, value) {//      
    var select = $("#" + id)[0];
    select.options.add(new Option(text, value));
}
function selectOneOption(id, selectValue) {//   ,      
    var select = $("#" + id)[0];
    var len = select.options.length;
    for (var i = 0; i < len; i++) {
        if (select.options[i].value == selectValue) {
            select.options[i].selected = true;
            break;
        }
    }
}
function selectOneOptionByIndex(id, index) {////    ,      

    var select = $("#" + id)[0];
    var len = select.options.length;
    if (index >= 0 && index <= len) {
        select.options[index].selected = true;
     }  
}