js 操作 dropdownlist
var DropDownList1 = document.getElementById("DropDownList控件ID"); //获取DropDownList控件的引用
var DropDownList1_Index = DropDownList1.selectedIndex; //获取选择项的索引
var DropDownList1_Value = DropDownList1.options[DropDownList1_Index].value; //获取选择项的值
var DropDownList1_Text = DropDownList1.options[DropDownList1_Index].text; //获取选择项的文本
注:textbox不能事先设置visible属性
block与inline两个元素:block元素的特点是,总是在新行上开始,高度,宽度,行高,边距都可以控制(块元素);Inline 元素的特点是,和其他元素在同一行上,不可控制(内嵌元素)
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 var txtddlWeight = document.getElementById("ddlWeight"); 2 var valddlWeight = txtddlWeight.options[txtddlWeight.selectedIndex].value; 3 if (valddlWeight == "0") { 4 document.getElementById("TxtWeight").style.display = "none"; 5 } 6 else { 7 document.getElementById("TxtWeight").style.display = "inline"; 8 } 9 10 txtddlWeight.onchange = function () { 11 var valddlWeight = txtddlWeight.options[txtddlWeight.selectedIndex].value; 12 if (valddlWeight == "0") { 13 document.getElementById("TxtWeight").style.display = "none"; 14 document.getElementById("TxtWeight").setAttribute("value", ""); 15 } else { document.getElementById("TxtWeight").style.display = "inline"; } 16 document.getElementById("TxtWeight").setAttribute("value", "1"); 17 18 }