在select中,载入时默认select为空白,选项内不显示空白项

有两种办法,一种纯css实现,一种借助js实现。

html:

<body onload="load()">  
    <select id="abc" >          
        <option >1</option>      
        <option >2</option>          
        <option >3</option>          
        <option >4</option>       
    </select>  
</body>  

先js

<script>    
function load()    
{    
    var x = document.getElementById("abc");    
    x.selectedIndex = -1;    
}    
</script>   

纯CSS

<option selected="selected" disabled="disabled"  style='display: none' value=''></option>  

纯css在ie8下 会有些问题 ,默认虽然是不显示,但下拉的时候回有第一个option 为空,但显示

原文地址:https://www.cnblogs.com/yang-C-J/p/7049372.html