﻿// JScript 文件
$.fn.size = function(){
    return $(this).get(0).options.length;
}

$.fn.getSelectedIndex = function(){
    return $(this).get(0).selectedIndex;
}


$.fn.getSelectedIndexValue = function(index){    
    return $(this).get(0).options[index].value;
}

$.fn.setSelectedIndexText = function(index,text){
        $(this).get(0).options[index].text = text;
}
$.fn.setSelectedValue = function(value){
    $(this).get(0).value = value;
}



$.fn.isExistItem = function(value){
    var isExist = false;
    var count = this.size();
    for(var i=0;i<count;i++){
        if($(this).get(0).options[i].value == value){
            isExist = true;
            break;
        }
    }
    return isExist;
}
$.fn.addFirstOption = function(text,value){
     if(this.size() == 0) 
        $(this).get(0).options.add(new Option(text,value),0);
}
$.fn.addOption = function(text,value){
    if(this.isExistItem(value)){
        alert("待添加项的值已存在");
    }
    else{
        var count = this.size() + 1;
        $(this).get(0).length = count;
        $(this).get(0)[count - 1] = new Option(text,value);
    }
}


$.fn.clearAll = function(){
    $(this).get(0).length = 0;
}

