この記事では、JSがSelect and DropdownListを単純な操作で操作する方法について説明します。参照のためにそれを共有してください。特定の実装方法は次のとおりです。
1. SELECT SERVER CONTROLS SELECT and DROPDOWNLIST JS
1。JSOperation Server Control Select
次のようにコードをコピーします
<オプション値= "0"> == == </option>を選択してください
<オプション値= "1"> yes </option>
<オプション値= "2"> no </option>
</select>
<script type = "text/javascript"言語= "javascript">
関数showmessage(){
if(document.getElementById( "selectid")。options [document.getElementById( "selectid")。selectedindex] .value == 1){
アラート(「こんにちは、最初のものを選んだ」);
document.getElementById( "txtcontractname")。setAttribute( "enable"、false);
}
else if(document.getElementById( "selectid")。options [document.getElementbyId( "selectid")。selectedindex] .value == 2){
アラート(「こんにちは、2番目のものを選んだ」);
}
}
</script>
// JS Operation Server Control DropdownList
<ASP:DropDownList ID = "ddlfolder" runat = "server" skinid = "ddlskin" autopostback = "false" onecrectedIndexChanged = "ddlfolder_selectedindexed">
<asp:listitem value = "0">オプション0 </asp:listitem>
<asp:listitem value = "1">オプション1 </asp:listitem>
</asp:ドロップダウンリスト>
<ASP:DropDownList ID = "ddlfolder" runat = "server" skinid = "ddlskin" autopostback = "false" onecrectedIndexChanged = "ddlfolder_selectedindexed">
<asp:listitem value = "0">オプション0 </asp:listitem>
<asp:listitem value = "1">オプション1 </asp:listitem>
</asp:ドロップダウンリスト>
JSコード:
コードコピーは次のとおりです。Document.getElementById( "ddlfolder")。value = "0"; // 0は選択するアイテムの値です
2。テキスト値の設定に従ってアイテムを選択します
コードコピーは次のとおりです。varDropdownListCurrencyNew = document.getElementByID( "ddlfolder");
for(i = 0; i <dropdownlistcurrencynew.options.length; i ++)
{
if(dropdownlistcurrencynew.options [i] .text == "option 0")
{
DropDownListCurrencyNew.options [i] .Selected = true;
}
}
2。JSドロップダウンリストの選択したアイテムの値とテキストを読む
価値:
コードコピーは次のとおりです。VARSELVALUE= DOCUMENT.GETELEMENTBYID( "DropDownList1")。オプション[document.getElementByID( "DropDownlist1")。
文章:
コードコピーは次のとおりです。VARSELTEXT= DOCUMENT.GETELEMENTBYID( "DropDownList1")。options [document.getElementByID( "DropDownlist1")。selectedIndex] .text;
この記事が、みんなのJSおよび.NETプログラミングに役立つことを願っています。