复制代码 代码如下:
HTML>
HEAD>
TITLE>下拉框模拟只读/TITLE>
script type="text/javascript">
//根据下拉框ID设置下拉框只读
function setReadOnly(obj_id){
var obj = document.getElementById(obj_id);
obj.onmouseover = function(){
obj.setCapture();
}
obj.onmouseout = function(){
obj.releaseCapture();
}
obj.onfocus = function(){
obj.blur();
}
obj.onbeforeactivate = function(){
return false;
}
}
/script>
/HEAD>
BODY>
span id="span_select">
select id="id_select">
option value="1">AAAAAAAAA/option>
option value="2">BBBBBBBBB/option>
option value="3">CCCCCCCCC/option>
option value="4">DDDDDDDDD/option>
/select>
/span>
script type="text/javascript">
setReadOnly("span_select");
/script>
!-- 直接设置下拉框只读 -->
select onbeforeactivate="return false" onfocus="this.blur()" onmouseover="this.setCapture()" onmouseout="this.releaseCapture()">
/BODY>
/HTML>
如果是ASP.NET ,则是下面的写法
复制代码 代码如下:
this.ddlSysCategory.Attributes.Add("onfocus","this.blur();");
this.ddlSysCategory.Attributes.Add("onbeforeactivate","return false");
this.ddlSysCategory.Attributes.Add("onmouseover","this.setCapture()");
this.ddlSysCategory.Attributes.Add("onmouseout","this.releaseCapture()");
您可能感兴趣的文章:- MVC实现下拉框联动效果(单选)
- 详解ASP.NET MVC之下拉框绑定四种方式
- ASP.NET MVC下拉框联动实例解析
- asp.net mvc下拉框Html.DropDownList 和DropDownListFor的常用方法
- 基于MVC3方式实现下拉列表联动(JQuery)
- asp.net 自制的单选、多选列表实现代码
- 在.net中用CheckBoxList实现单选
- asp.net中js+jquery添加下拉框值和后台获取示例
- ASP.NET中DropDownList下拉框列表控件绑定数据的4种方法
- MVC5下拉框绑定的方法(单选)