JQuery操作select标签(转)

江佐
2023-12-01

原文: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 ;
}
}

判断checklist,radiolist是否为空: 

$(id).find('input:radio/check:checked').next().text()==""

获取服务器控件ID:

var id = $("*[id$=id]");

模糊查找ID

var year = $("tr[id*='trYear_']");

清空 Select:

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

转载于:https://www.cnblogs.com/pfs1314/archive/2011/05/13/2045642.html

 类似资料: