【发布时间】:2011-08-03 22:09:46
【问题描述】:
我们有一个带有三个 ListItem 的 RadioButtonList。当用户进行选择时,我们希望显示一个确认框。如果他们点击取消,我们只想撤消选择更改。下面的代码在所有情况下都可以正常工作 - 但 IE 7、8 和 9。在 IE 中,在 return false 执行后没有选择任何 ListItem,但在所有其他情况下,只有下面的代码,选择被撤消,并且然后像我们想要的那样选择先前选择的项目。你没有工作吗?
标记:
<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:
function confirmSubmit(listItem, e) {
var agree = confirm("Do you really want to change the value?");
if (!agree) {
return false;
}
else {
document.forms[0].submit();
}
}
【问题讨论】:
标签: javascript asp.net internet-explorer