1. 在后台添加dropdownlist的“onchange”属性,函数参数是当前选中项的value值:

drp.Attributes.Add("onchange", "Change(this.options[this.selectedIndex].value)");   

2.js获取dropdownlist当前选中项的text和value:

//获取option Value 

Value = document.getElementById("<%= drp.ClientID %>").value;     

//获取option text

Text = document.getElementById("<%= drp.ClientID %>").options[document.getElementById("<%= drp.ClientID %>").selectedIndex].text;  

3. js删除dropdownlist所有项:

function RemoveAllOption(drp)       //清除DropDownList的所有项
    {
        var i = 0;
        for(i = drp.length; i >= 0; i--)
        {
           drp.options.remove(i);
        }
    }

var drp= document.getElementById("<%=drp.ClientID %>");

4.js赋值dropdownlist

itemText = new Array("序列号", "BOM号", "订单号");
itemValue = new Array("0", "1", "2"); 

for (i = 0; i < itemText.length; i++) {
            var newOption = document.createElement("OPTION");
            newOption.text = itemText[i];
            newOption.value = itemValue[i];
            ddl.options.add(newOption);
        }

posted on 2011-07-11 20:43  飞翔-方向 积累 沉淀  阅读(1326)  评论(0)    收藏  举报