下拉框只读

来源:互联网 发布:阿里云企业邮箱条件 编辑:程序博客网 时间:2024/05/16 15:06

html中,select下拉框中是没有readonly这个属性的,只有disabled。但是用disabled就无法将下拉框中的数据读出来,所以要想办法将select下拉框设置成只读的。

将select下拉框设置成readonly 的两种办法。

第一种:

[html] view plaincopyprint?
  1. <script>varf=s.selectedIndex</script> 
  2. <select name=sonchange="selectedIndex=f">  
  3. <option>1</option>  
  4. <option selected>2</option>   
  5. </select>   

第二种:

[html] view plaincopyprint?
  1. <spanonmousemove="this.setCapture();"onmouseout="this.releaseCapture();"onfocus="this.blur();"> 
  2. <select >  
  3. <option>1</option>  
  4. <option selected>2</option>  
  5. </select> 
  6. </span> 

其中onmousemove="this.setCapture();" onmouseout="this.releaseCapture();" 屏蔽了鼠标事件,

onfocus="this.blur();"屏蔽了键盘事件,onfocus="this.blur();"表示该对象将获得焦点时就让它失去焦点,按键盘的TAB键时跳过它,使下一个控件获得焦点。

原创粉丝点击