<select id="seldriver" name="seldriver">
 <option value ="AAA">AAA</option>
 <option value ="BBB">BBB</option>
 <option value ="CCC">CCC</option>
 <option value ="DDD">DDD</option>
</select>这是select中本来的值根据条件需要,我传一个"CCC"的值过来。。我想select中直接显示为 "CCC".

解决方案 »

  1.   

    <option value ="CCC" selected>CCC</option>
     
      

  2.   

    当某列表项为默认值时,设置它为selected
      

  3.   

    如果是ASP的话,可以根据VB脚本中的变量去设置哪一个为selected.
      

  4.   

    最简单的方法 document.getElementById("seldriver").value='CCC';//这个CCC一定要在下拉表中存在,如果不存在,下拉表第一项会为空
      

  5.   

    我是传想 传入 js 中实现...
      
      document.getElementById('seldriver').value = dir_Name;
      
     <select id="seldriver" name="seldriver">
    ....</select>请问怎么实现。
      

  6.   


    document.getElementById("seldriver").value = "CCC";
      

  7.   

    不管你想怎么实现。。你最后把你想要首先被选择的那个设置成SELECTED就行了
      

  8.   

     function selected(v)
                {
                    var obj =   document.getElementById('seldriver');
                    for(var i = 0 ; i < obj.options.length ; i++)
                    {
                         if(obj.options[i].value === v)
                         {
                             obj.selectedIndex = i;
                             return;
                         }
                    }
                }
      

  9.   

    页面传值 比如aa.aspx?v=CCC
    然后脚本里边
    document.getElementById('seldriver').value = "<%=Request.QueryString["v"]%>";
      

  10.   


    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title></title>
    <script type="text/javascript" src="jquery-1.4.2.min.js"></script>
    <script type="text/javascript">
    $().ready(function(){
    $("#btnSelect").click(function(){
    var name = $("#txtName").val();
    if(!name) return;
    $("select").find("option").each(function(){
    this.selected = $(this).text() == name;
    });
    });
    });
    </script>
    </head>
    <body>
    <select id="seldriver" name="seldriver">
     <option value ="AAA">AAA</option>
     <option value ="BBB">BBB</option>
     <option value ="CCC">CCC</option>
     <option value ="DDD">DDD</option>
    </select><br/>
    <input type="text" id="txtName"/>
    <button type="button" id="btnSelect">选择</button>
    </body>
    </html>