JQuery操作select标签

原文:http://blog.sina.com.cn/s/blog_494a28140100muf1.html

获取select 选中的 text:

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

获取select选中的 value:
  
    
$( " #ddlRegType " ).val();
获取select选中的索引:
  
    
$( " #ddlRegType " ).get( 0 ).selectedIndex;
设置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 " ).size();
for ( var i = 0 ;i < count;i ++ )
{
if ($( " #ddlRegType " ).get( 0 ).options[i].text == text)
{
$(
" #ddlRegType " ).get( 0 ).options[i].selected = true ;

break ;
}
}
清空 Select:
  
    
$( " #ddlRegType " ).empty();

你可能感兴趣的:(jquery)