首页 > 编程 > .NET > 正文

asp.net 实现下拉框只读功能

2024-07-10 13:23:15
字体:
来源:转载
供稿:网友

复制代码 代码如下:


<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>
<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()">
</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()");

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表