ASP.NET/JAVASCRIPT从RadioButton值禁用下拉列表(客户端)
目前我有三个单选按钮:ASP.NET/JAVASCRIPT从RadioButton值禁用下拉列表(客户端),javascript,asp.net,Javascript,Asp.net,目前我有三个单选按钮: <asp:RadioButton ID="rbShowAll" runat="server" CssClass="radio-inline" GroupName="grpReadStatus" onchange="disableDDL()"/> <asp:RadioButton ID="rbIssuedTo" runat="server" CssClass="radio-inline" GroupName="grpReadStatus" onchange
<asp:RadioButton ID="rbShowAll" runat="server" CssClass="radio-inline" GroupName="grpReadStatus" onchange="disableDDL()"/>
<asp:RadioButton ID="rbIssuedTo" runat="server" CssClass="radio-inline" GroupName="grpReadStatus" onchange="disableDDL()"/>
<asp:RadioButton ID="rbReceivedFrom" runat="server" CssClass="radio-inline" GroupName="grpReadStatus" onchange="disableDDL()"/>
但它不起作用。有人能就此提出建议吗?非常感谢您的帮助。谢谢我已经为您创建了一个有效的代码段,有很多拼写错误,这就是为什么它不起作用,我已经全部更正:)看一看
函数disableDDL(){
document.getElementById(“ddlBuyer”).disabled=false;
document.getElementById(“ddlSeller”).disabled=false;
if(document.getElementById(“rbShowAll”).选中){
//警报(“rbShowAll”);
document.getElementById(“ddlBuyer”).disabled=true;
document.getElementById(“ddlSeller”).disabled=true;
}else if(document.getElementById(“rbIssuedTo”).选中){
//警报(“rbIssuedTo”);
document.getElementById(“ddlSeller”).disabled=true;
}else if(document.getElementById(“rbReceivedFrom”)。选中){
//警报(“rbReceivedFrom”);
document.getElementById(“ddlBuyer”).disabled=true;
}//否则{
//警报(“其他”);
//}
}
全部显示
发给
收到
选择买家
买方1
选择卖家
卖方1
asp:RadioButton被呈现为span元素,其中包含单选按钮,因此您放置的事件将被分配给span元素,并且不起作用。
而是直接使用:
相应地修改html
<input type="radio" id="rbShowAll" class="radio-inline" name="grpReadStatus" onchange="javascript:disableDDL()">Show all
<input type="radio" id="rbIssuedTo" class="radio-inline" name="grpReadStatus" onchange="javascript:disableDDL()">Issued to
<input type="radio" id="rbReceivedFrom" class="radio-inline" name="grpReadStatus" onchange="javascript:disableDDL()">Recieved from
<select id="ddlBuyer">
<option>Select Buyer</option>
<option>Buyer 1</option>
</select>
<select id="ddlSeller">
<option>Select Seller</option>
<option>Seller 1</option>
</select>
function disableDDL() {
if (document.getElementById("rbShowAll").checked) {
document.getElementById("ddlBuyer").disabled = true;
document.getElementById("ddlSeller").disabled = true;
}
else if (document.getElementById("rbIssuedTo").checked) {
document.getElementById("ddlSeller").disabled = true;
document.getElementById("ddlBuyer").disabled = false;
}
else if (document.getElementById("rbReceivedFrom").checked) {
document.getElementById("ddlSeller").disabled = false;
document.getElementById("ddlBuyer").disabled = true;
}
<input type="radio" id="rbShowAll" class="radio-inline" name="grpReadStatus" onchange="javascript:disableDDL()">Show all
<input type="radio" id="rbIssuedTo" class="radio-inline" name="grpReadStatus" onchange="javascript:disableDDL()">Issued to
<input type="radio" id="rbReceivedFrom" class="radio-inline" name="grpReadStatus" onchange="javascript:disableDDL()">Recieved from
<select id="ddlBuyer">
<option>Select Buyer</option>
<option>Buyer 1</option>
</select>
<select id="ddlSeller">
<option>Select Seller</option>
<option>Seller 1</option>
</select>
function disableDDL() {
if (document.getElementById("rbShowAll").checked) {
document.getElementById("ddlBuyer").disabled = true;
document.getElementById("ddlSeller").disabled = true;
}
else if (document.getElementById("rbIssuedTo").checked) {
document.getElementById("ddlSeller").disabled = true;
document.getElementById("ddlBuyer").disabled = false;
}
else if (document.getElementById("rbReceivedFrom").checked) {
document.getElementById("ddlSeller").disabled = false;
document.getElementById("ddlBuyer").disabled = true;
}