IE在javascript函数返回false后取消选择RadioButtonList
我们有一个带有三个列表项的RadioButton列表。当用户进行选择时,我们希望显示一个确认框。如果他们点击cancel,我们只希望取消选择更改。下面的代码在任何情况下都可以正常工作,但-IE 7、8和9除外。在IE中,执行返回false后不会选择任何ListItems,但在所有其他情况下,仅使用下面的代码,就会撤消选择,然后选择先前选择的项,就像我们希望的那样。你没有工作吗 标记:IE在javascript函数返回false后取消选择RadioButtonList,javascript,asp.net,internet-explorer,Javascript,Asp.net,Internet Explorer,我们有一个带有三个列表项的RadioButton列表。当用户进行选择时,我们希望显示一个确认框。如果他们点击cancel,我们只希望取消选择更改。下面的代码在任何情况下都可以正常工作,但-IE 7、8和9除外。在IE中,执行返回false后不会选择任何ListItems,但在所有其他情况下,仅使用下面的代码,就会撤消选择,然后选择先前选择的项,就像我们希望的那样。你没有工作吗 标记: <asp:RadioButtonList ID="RadioButtonList1" runat="ser
<asp:RadioButtonList ID="RadioButtonList1" runat="server" RepeatDirection="Horizontal" OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged" AutoPostBack="False">
<asp:ListItem Selected="True" onClick="return confirmSubmit(this, event);">Value 1</asp:ListItem>
<asp:ListItem onClick="return confirmSubmit(this, event);">Value 2</asp:ListItem>
<asp:ListItem onClick="return confirmSubmit(this, event);">Value 3</asp:ListItem>
</asp:RadioButtonList>
最直接的跨浏览器兼容处理方法是使用javascript库。下面是一个与代码一起使用的解决方案
<script type="text/javascript">
var rblContainer;
var lastChecked;
$(document).ready(function () {
rblContainer = $('#<%= RadioButtonList1.ClientID %>');
lastChecked = rblContainer.children().find('input[checked]');
});
function confirmSubmit(listItem, e) {
var l = $(listItem);
var agree = confirm("Do you really want to change the recipient type?");
if (!agree) {
lastChecked.attr("checked", "checked");
return false;
}
else {
lastChecked = l;
document.forms[0].submit();
}
}
</script>
var RBL容器;
var lastChecked;
$(文档).ready(函数(){
rblContainer=$(“#”);
lastChecked=rblContainer.children().find('input[checked]');
});
功能确认提交(列表项,e){
var l=$(列表项);
var agree=confirm(“您真的想更改收件人类型吗?”);
如果(!同意){
lastChecked.attr(“checked”、“checked”);
返回false;
}
否则{
lastChecked=l;
document.forms[0]。提交();
}
}
<script type="text/javascript">
var rblContainer;
var lastChecked;
$(document).ready(function () {
rblContainer = $('#<%= RadioButtonList1.ClientID %>');
lastChecked = rblContainer.children().find('input[checked]');
});
function confirmSubmit(listItem, e) {
var l = $(listItem);
var agree = confirm("Do you really want to change the recipient type?");
if (!agree) {
lastChecked.attr("checked", "checked");
return false;
}
else {
lastChecked = l;
document.forms[0].submit();
}
}
</script>