代码期间,将写代码过程较好的代码段备份一次,下面资料是关于用JS和C#分别在前端和后端控制下拉框为只读的方法的代码,应该对各位朋友有较大用途。
<HTML>
<HEAD>
<TITLE>下拉框模拟只读</TITLE>
<script type="text/javascript">
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后端C#代码
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()");
原文地址:https://blog.51cto.com/14129678/2403586
时间: 2024-10-07 23:24:44