[英]radiobuttonlist
大家好,我有一个带有多个单选按钮列表的页面,每个列表都有一个清除选择按钮,如果按下该按钮则可以清除列表。 问题是我当前的代码,如果我按清除选择按钮,它将清除页面上的所有单选按钮列表。 我如何修改我的代码以仅清除所需的单选按钮列表。 这是代码片段。
<asp:RadioButtonList ID="rdoQuestionChoice" runat="server" Visible="false" CssClass="Aligntext" OnSelectedIndexChanged="ddlChoiceList_SelectedIndexChanged" />
<asp:Button ID="clearRdoQuestionChoice" runat="server" Visible="false" Text="Clear Selection" OnClientClick="clearRdoQuestionChoice_ClearRadioList(); return false;" />
<script language="javascript" type="text/javascript">
function clearRdoQuestionChoice_ClearRadioList() {
$("table[id$=rdoQuestionChoice] input:radio").each(function (i, x) {
if ($(x).is(":checked")) {
$(x).removeAttr("checked");
}
});
}
</script>
您是否尝试过仅更改单选按钮列表的选择索引? 像这样->
C#(已测试)
rdoQuestionChoice.SelectedIndex = -1
Javascript(未经测试)
window.addEvent('domready', function() {
$("rdoQuestionChoice").checked = false;
});
或者,您可以在此处查看更多信息和其他javascript函数: http : //www.tek-tips.com/viewthread.cfm? qid= 1436752
我能够解决这个问题。
在我的基础.cs类中,我在Page_Load(object sender,EventArgs e)函数中添加了以下代码行
clearRdoQuestionChoice.OnClientClick = "clearRdoQuestionChoice_ClearRadioList('" + rdoQuestionChoice.ClientID + "')";
在我的javascript函数中,进行了以下更改
function clearRdoQuestionChoice_ClearRadioList(radioButtonListID) {
var elementRef = document.getElementById(radioButtonListID);
var inputElementArray = elementRef.getElementsByTagName('input');
for (var i = 0; i < inputElementArray.length; i++) {
var inputElement = inputElementArray[i];
inputElement.checked = false;
}
return false;
}
我将.aspx类更改为以下内容。 我基本上从asp:button中删除了OnClientClick属性
<asp:RadioButtonList ID="rdoQuestionChoice" runat="server" Visible="false" CssClass="Aligntext" OnSelectedIndexChanged="ddlChoiceList_SelectedIndexChanged" />
<asp:Button ID="clearRdoQuestionChoice" runat="server" Visible="false" Text="Clear Selection" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.