一:js 设置DropDownList选中某项

1.根据Value值设置选中某项    例子如下:

HTML代码:

<asp:DropDownList ID="ddlFolder" runat="server" SkinID="ddlSkin" AutoPostBack="false" OnSelectedIndexChanged="ddlFolder_SelectedIndexChanged">        <asp:ListItem Value="0">选项0</asp:ListItem>     <asp:ListItem Value="1">选项1</asp:ListItem>      </asp:DropDownList>    
<asp:DropDownList ID="ddlFolder" runat="server" SkinID="ddlSkin" AutoPostBack="false" OnSelectedIndexChanged="ddlFolder_SelectedIndexChanged"> <asp:ListItem Value="0">选项0</asp:ListItem> <asp:ListItem Value="1">选项1</asp:ListItem> </asp:DropDownList>

JS代码:

document.getElementById("ddlFolder").value="0";//0为你要选中的项的value  

2.根据Text值设置选中某项

var DropDownListCurrencyNew 
js操作DropDownList大全    
=  document.getElementById("ddlFolder");
js操作DropDownList大全
for(i = 0; i < DropDownListCurrencyNew.options.length; i++)
   {
          
if(DropDownListCurrencyNew.options[i].text == "选项0")    
           {
               DropDownListCurrencyNew.options[i].selected 
= true
          }

   }

二:js读取DropDownList选中项的value和text

Value:

var selValue =document.getElementById("DropDownList1").options[document.getElementById("DropDownList1").selectedIndex].value;

Text:

var selText = document.getElementById("DropDownList1").options[document.getElementById("DropDownList1").selectedIndex].text

相关文章:

  • 2022-12-23
  • 2021-12-28
  • 2021-05-31
  • 2021-08-02
  • 2021-07-05
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-01-17
  • 2022-12-23
  • 2021-10-03
  • 2021-10-22
  • 2021-07-08
相关资源
相似解决方案