`
lgx2351
  • 浏览: 171746 次
  • 性别: Icon_minigender_1
  • 来自: 福州
社区版块
存档分类
最新评论

如何设置Select下拉框的ReadOnly属性

阅读更多

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/youbl/archive/2009/02/27/3942578.aspx

 

因为Select下拉框只支持disabled属性,不支持readOnly属性,

而在提交时,disabled的控件,又是不提交值的,在网上搜索了一下,发现有个很好的方法:

<select name="select123" onbeforeactivate="return false;" onfocus="this.blur();" onmouseover="this.setCapture();" onmouseover="this.releaseCapture();">
    <option>aaa</option>
</select>

 

或者使用如下的js脚本:

<select name="select123">
    <option>aaa</option>
</select>

<script type="text/javascript">

SetReadOnly(document.getElementById("select123"));
function SetReadOnly(obj){
    if(obj){
        obj.onbeforeactivate = function(){return false;};
        obj.onfocus = function(){obj.blur();};
        obj.onmouseover = function(){obj.setCapture();};
        obj.onmouseout = function(){obj.releaseCapture();};
    }
}

</script> 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics