jsp jquery 兑现级联菜单,jquery对select元素的简单操作

jsp jquery 实现级联菜单,jquery对select元素的简单操作
用于触发select的事件的方法有click()和change()
click():是当对象被点击了才触发
change():是当对象发生了变化才触发
下面简单记录下jquery对select的常用操作:
1. 获取select 选中的 text:
 $("#id").find("option:selected").text();


2. 获取select选中的 value:
 $("#id").val();


3. 获取select选中的索引:
 $("#id").get(0).selectedindex;


4. 设置select 选中的索引:
 $("#id").get(0).selectedIndex=1; //注意I大写


5. 设置select 选中的value:
    $("#id").attr("value","normal“);
    $("#id").val("normal");
    $("#id").get(0).value = value;


6. 设置select 选中的text:
var count=$("#ddlregtype option").length;
  for(var i=0;i<count;i++)  
     {           if($("#ddlregtype ").get(0).options[i].text == text)  
        {  
            $("#ddlregtype ").get(0).options[i].selected = true;  
            break;  
        }  
    }


7. 设置select option项:
$("#select_id").append("<option value='value'>text</option>");  //添加一项option
$("#select_id").prepend("<option value='0'>请选择</option>"); //在前面插入一项option
$("#select_id option:last").remove(); //删除索引值最大的option
$("#select_id option[index='0']").remove();//删除索引值为0的option
$("#select_id option[value='3']").remove(); //删除值为3的option
$("#select_id option[text='4']").remove(); //删除text值为4的option