如何使下拉列表和单选按钮为只读?

问题描述

我希望将下拉列表和单选按钮设置为只读,以便可以接受输入。我不想禁用它。

下拉列表...

<select name="ctitle" readonly>
    <option selected value=" ">&nbsp;</option>
        <%do until rsPositions.eof
            strContent = rsPositions("descrip")
            StrValue   = rtrim(rsPositions("descrip"))
            intThisId = rsPositions("id")
            if ucase(rtrim(strCtitle)) = ucase(strValue) then%> 
                <option selected value="<%=strValue%>"><%=StrContent%></option>
            <%else  
                if not StrReadOnly then%>
                    <option value="<%=strValue%>"><%=StrContent%></option>
                <%end if  
            end if      
            rsPositions.movenext
        loop%>
</select>

单选按钮...

<%if StrCurtype="H" then%>
    <input type="radio" name="curtype" value="H" checked >
<% else%>  
    <input type="radio" name="curtype" value="H">
<% end if%>Hourly&nbsp;&nbsp;
<% if StrCurtype="S" then%>
    <input type="radio" name="curtype" value="S" checked >
<% else%>  
    <input type="radio" name="curtype" value="S" >
<% end if%>
Salary(<%=StrPayCycleDes%>)&nbsp;&nbsp;&nbsp;&nbsp;

解决方法

我不认为这些元素支持readonly。您将不得不禁用它们。如果仍然需要收集值,请考虑使用隐藏的输入。

,

您可以尝试这样做:

<input type="radio" name="name" checked onclick="this.checked = true;" />

或者您的单选按钮代码可能是这样的:

if StrCurtype="H" then%>
   <input type="radio" name="curtype" value="H" checked onClick="return false;">
<% else%>  
   <input type="radio" name="curtype" value="H" onClick="return false;">
<% end if%>Hourly&nbsp;&nbsp;
<% if StrCurtype="S" then%>
     <input type="radio" name="curtype" value="S" checked onClick="return false;">
<% else%>  
     <input type="radio" name="curtype" value="S" onClick="return false;">
<% end if%>Salary(<%=StrPayCycleDes%>)