var sel = document.formname.selectname;
for(var i=0;i<sel.options.length;i++){
  if(sel.options[i].value=="xxxx"){
     sel.options[i].selected = true;
     break;
  } 
}

解决方案 »

  1.   

    试验了一下,还真的可以。
    问一下,可不可以设置DropDownList的属性值呢?
      

  2.   

    怎么我照你编写总是 错呢?帮我看看代码.
    1、DropDownCheckList的控件名:CDept
    2、窗体名为Form1。
    var sel = document.Form1.Drp_CDept;
    alert(sel);
    for(var i=0;i<sel.options.length;i++)
    {
    if(sel.options[i].value=="1004")
    {
    sel.options[i].selected = true;

    else if((ndave>1002)&&(ndave<1006)&&(sel.options[i].value =="1005"))
    {
    sel.options[i].selected =true;
    }
    else
    {
    sel.options[i].selected=false;
    }
    }
    alert(sel)提示为NULL呀
      

  3.   

    var objList=document.getElementById("Drp_CDept");
      if(typeof(objList)=="object")
     { 
         
     var nCount=objList.children.item.length;
     
    for(var i=0; i<nCount-1;i++)
    {
     var item=objList.children.item(0); 
     var chItem =item.children.item(i);
            //
     if ( typeof(chItem)=="object")
     { 
      alert(chItem);
     /*
    if(item.children.item(i).value =="1004")
    {
    item.children.item(i).selected =true;
    }
    else if((ndave>1002)&&(ndave<1006)&&(objList.children.item(i).value =="1005"))
    {
    objList.children.item(i).selected =true;
    }
    else
    {
    objList.children.item(i).selected=false;
    }*/
    }
           
    }
    }
    请问带注释部分怎么表达
      

  4.   

    <ddcc1:DropDownCheckList ID="ddclRank" runat="server" DisplayBoxCssClass="ddcl" DisplayTextList="Labels"  ClientCodeLocation="../../javascript/DropDownCheckList.js" Width="153px">                                                                   </ddcc1:DropDownCheckList>   // 写在PageLoad事件中
    for (int i = 0; i < ddclRank.Items.Count; i++)
                    {
                        ddclRank.Items[i].Selected = true;
                    }