radiobuttonlist
本文关键字:radiobuttonlist | 更新日期: 2023-09-27 18:08:09
嘿,伙计们,我有一个页面,有多个单选按钮和一个清除选择按钮,每个列表清除列表,如果按下。问题是我当前的代码,如果我按下清除选择按钮,它清除页面上的所有单选按钮。我如何修改我的代码,只是清除我想要的单选按钮列表。下面是代码片段。
<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(对象发送者,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" />