我正在創建一個包含兩個div標籤和兩個單選按鈕的網站。 div將根據所選的單選按鈕顯示。在頁面加載時,我傳遞主頁面的單選按鈕的值,並相應地顯示div。它適用於Chrome和Firefox,但在IE中顯示問題。我正在使用IE 11.我還沒有嘗試過其他版本的IE。 我的代碼如下:Javascript onload未在IE中觸發
<asp:RadioButton ID="mail_stat" Text="Mailwise Statistics" runat="server" GroupName="stat_select" onclick="ch(1)" ClientIDMode="Static" />
<asp:RadioButton ID="aggegrate_stat" Text="Aggegrate Statistics" runat="server" GroupName="stat_select" onclick="ch(2)" ClientIDMode="Static" />
<div id="first">
<table border="0">
<tr>
<td>
<asp:Label ID="lbl_pro_id" runat="server" Text="Promotion Id"></asp:Label> </td>
<td>
<asp:TextBox ID="txt_pro_id" runat="server" Width="101px"></asp:TextBox></td>
</tr>
<tr>
<td>
<asp:Label ID="lbl_sub" runat="server" Text="Subject"></asp:Label></td>
<td>
<asp:TextBox ID="txt_sub" runat="server" Width="301px" Height="16px"></asp:TextBox></td>
</tr>
</table>
</div>
<div id="second">
<table border="0">
<tr>
<td>
<asp:TextBox ID="txtStartDate" runat="server" required="true" placeholder="Start Date"></asp:TextBox></td>
<td>
<asp:TextBox ID="txtEndDate" runat="server" required="true" placeholder="End Date"></asp:TextBox></td>
</tr>
</table>
</div>
我的Java腳本如下:
<%--Javascript for radiobuttion on load--%>
<script type="text/javascript">
onload = function() {
if (mail_stat.checked == true)
{
ch(1);
}
else if (aggegrate_stat.checked == true)
{
ch(2);
}
}
</script>
<%--Javascript for radiobuttion--%>
<script type="text/javascript">
$('#first').hide();
$('#second').hide();
$('stat2').hide();
function ch(id) {
if (id == '1') {
$('#first').show();
$('#second').hide();
$('#stat2').hide();
}
else if (id == '2') {
$('#first').hide();
$('#second').show();
$('#stat2').show();
}
}
</script>
請幫助。
被取出的元素?嘗試'$(「#mail_stat」)。is(「:checked」)' – rps
看看:[ASP.NET AJAX pageLoad()和JavaScript window.onload之間的區別是什麼?](http://stackoverflow.com/問題/ 602441/whats-the-different-between-asp-net-ajax-pageload-and-javascript-window-onloa) – Givi