<SELECT id=\"CertID\"  name=\"CertID\" selected="+str[3]+">";
<OPTION value=0>-请选择-</OPTION>";
<OPTION value=1>初级</OPTION>";
</select>
这样赋值不行,怎么才赋值呢? str[3] 是数组,我从数据库读出来的值

解决方案 »

  1.   

    这样的 select 没有selected属性
    你可以判断下str[3]是多少
    然后给option里value是这个的赋值
    或者是selectedIndex= //这个是序号,可不是什么值哦
      

  2.   

    <select id="CertID"  name="CertID">
    <OPTION value="0">-请选择-</OPTION>
    <OPTION value="1">初级</OPTION>
    </select>
    <script>
    var str = [0,1];
    onload = function(){
      document.getElementById("CertID").value = str[1];
    }
    </script>
      

  3.   

    4. $("#CertID option[index='"+str[3]+"']").attr("selected","true");
    5. $("#CertID option[value='"+str[3]+"']").attr("selected","true");
    5. $("#CertID option[text='"+str[3]+"']").attr("selected","true");你读出来的str[3] 是index,value,还是text  放进去就可以了