list.options[list.length-1].selected=true;
or
list.value=id

解决方案 »

  1.   

    list.options[list.length-1].selected=true;
    or
    list.value=id
    这段是连起来一块用的?
      

  2.   

    function optionsCheckTo(list_box,val){
    for(var i=0;i<list_box.options.length;i++){
    if(list_box.options[i].value == val){
    list_box.options[i].selected = true ;
    return ;
    }
    }
    return ;
    }
      

  3.   

    var n = new Option();
    n.text = "1";
    n.value = "1";
    list_box.options.add(n,0);
      

  4.   

    var n = new Option();
    n.text = "1";
    n.value = "1";
    list_box.options.add(n,0);
    这是添加了,可是如何让添加的放到第一位呢?
      

  5.   

    <script>
    function aa()
    {
      var myArray = new Array(list.options.length);
      myArray[0] = new Array(2)
      myArray[0][0] = list.options.length
      myArray[0][1] = list.options.length  var len = list.options.length + 1
      for (i=0;i<list.options.length;i++)
      {
        myArray[i+1] = new Array(2)
        myArray[i+1][0] = list.options[i].value
        myArray[i+1][1] = list.options[i].text
      }
      
      list.options.length = 0;
      
      for (j=0;j<len;j++)
      {
        var oOption = document.createElement("OPTION");
        oOption.text = myArray[j][0]
        oOption.value = myArray[j][1]
        list.add(oOption);
      }
      
      
    }
    </script><select name="list" size="1">
    </select><input type="button" value="add" onclick="aa()">