参考引用:
HTML中Select不用Disabled实现ReadOnly的效果-javascript技巧
<select onbeforeactivate="return false" οnfοcus="this.blur()" οnmοuseοver="this.setCapture()" οnmοuseοut="this.releaseCapture()"> <option>1</option></select>
同理,在ASP.NET中的应用
在asp.net页面中针对RadioButtonLis、RadioButton、DropDownList、HtmlSelect等控件标签中添加οnmοuseοver="this.setCapture()" οnmοuseοut="this.releaseCapture()"即可(字体颜色也可以直接设置或通过css设置了)。
如:
<asp:RadioButtonList ID="rdoP_Type" runat="server" RepeatColumns="2" RepeatLayout="Flow" οnmοuseοver="this.setCapture()" οnmοuseοut="this.releaseCapture()" ForeColor="#FF9966">
<asp:ListItem Value="Y">是 </asp:ListItem>
<asp:ListItem Value="N">否 </asp:ListItem>
</asp:RadioButtonList>
在程序中,可以这样添加:
以VB.NET为例:
rdoP_Type.Attributes.Add("onmouseover","this.setCapture()")
rdoP_Type.Attributes.Add("onmouseout","this.releaseCapture()")
分别在IE和FF浏览器下测试,发现IE测试没问题,但是FF并不支持(setCapture和releaseCapture,FF有自己的),再加个属性试试,变成这样
rdoP_Type.Attributes.Add("onmouseover","this.setCapture()") ’IE支持,FF不支持
rdoP_Type.Attributes.Add("onclick","return false") ‘让FF支持
多个控件的情况下,可以通过遍历设置属性:
For Each t As Control In ControlsIf TypeOf (t) Is RadioButtonList Then
Dim t1 As RadioButtonList = CType(t, RadioButtonList)
t1.Attributes.Add("onmouseover","this.setCapture()")
t1.Attributes.Add("onmouseout","this.releaseCapture()")
t1.Attributes.Add("onclick","return false")
Next
在此之前,试过其他方法,不太理想,在此记录一下,以备需要时参考:
t1.Attributes.Add("style", "color:blue") 'FF支持,IE不兼容
t1.Attributes.Add("onclick", "return false")
t1.Attributes.Add("onclick", "this.checked=!this.checked") ’
t1.Attributes.Add("onclick", " if(rdoP_Type_0.checked) rdoP_Type_1.checked=!rdoP_Type_1.checked;") ‘有些效果,但需要继续完善判定方法。