

一、js选中服务器控件select与dropdownlist
1. js操作服务器控件select
 代码如下:
 function showMessage() {
 if (document.getElementById("selectID").options[document.getElementById("selectID").selectedIndex].value == 1) {
 alert("你好,你选择了第 1 个");
 document.getElementById("txtContractName").setAttribute("enable",false);
 }
 else if (document.getElementById("selectID").options[document.getElementById("selectID").selectedIndex].value == 2) {
 alert("你好,你选择了第 2 个");
 }
 }
 script>
//js操作服务器控件dropdownlist
 
 选项0 
 选项1 
 
 
 选项0
 选项1 
JS代码:
 代码如下:document.getElementById("ddlFolder").value="0";//0为你要选中的项的value
2. 根据Text值设置选中某项
 代码如下:var DropDownListCurrencyNew = document.getElementById("ddlFolder");
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;
希望本文所述对大家的js与.net程序设计有所帮助。
