代碼期間,將寫代碼過程較好的代碼段備份一次,下面資料是關於用JS和C#分別在前端和後端控制下拉框爲只讀的方法的代碼,應該對各位朋友有較大用途。javascript
<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()");