ITeye博客

jquery获得select option的值 和对select option的操作

java4evero · 2011-12-21 16:34 · java · jquery获得select option的值 和对select option的操作 · Markdown

获取Select : 获取select 选中的 text :

   $("#ddlRegType").find("option:selected").text();

获取select选中的 value:

  $("#ddlRegType ").val();

获取select选中的索引:

    $("#ddlRegType ").get(0).selectedIndex;

设置select: 设置select 选中的索引:

     $("#ddlRegType ").get(0).selectedIndex=index;//index为索引值

设置select 选中的value:

    $("#ddlRegType ").attr("value","Normal“);
    $("#ddlRegType ").val("Normal");
    $("#ddlRegType ").get(0).value = value;

设置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;  
        }  
    }
$("#select_id option[text='jQuery']").attr("selected", true);

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。