2017-10-14 113 views
0

我有兩種類型的用戶(temp/permanent)的註冊頁面,我只需要向每個用戶顯示部分表單。我試圖通過使用jQuery隱藏某些div元素來實現此目的。問題是我的DIV元素暫時隱藏,並在一秒鐘內重新出現。我試着尋找多個解決方案,但似乎沒有工作。這是我的代碼。Asp.net - jquery需要兩次點擊才能隱藏div

<script> 
     $(document).ready(function() { 
      $("#<%=releasetype.ClientID%>").click(function() { 
       var reltype = $("input[name='<%=releasetype.UniqueID%>']:radio:checked").val(); 
       if (reltype == "Temporary") { 
        document.getElementById('pm').style.display = 'none'; 
       } else if (reltype == "Permanent") { 
        document.getElementById('pm').style.display = 'block'; 
       } 
      }); 

     }); 
</script> 

的.aspx

<asp:RadioButtonList ID="releasetype" cssclass="radio" runat="server" AutoPostBack="True" RepeatDirection="Vertical"> 
       <asp:ListItem>Temporary</asp:ListItem> 
       <asp:ListItem>Permanent</asp:ListItem> 
</asp:RadioButtonList> 

      <div id="pm" class="form-horizontal"> 
<asp:Label ID="Label8" runat="server" Text="PrimaryID" Font-Bold="True"></asp:Label> 
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>    
      </div> 

我嘗試使用event.preventDefault(); &返回false;在我的代碼中。但是這兩種方法都沒有阻止頁面刷新。

+0

請顯示實際的HTML代碼,而不是我們無法輕易再現的服務器端代碼。 [mcve] – CBroe

+0

嗨你正在使用ASP .NET的Web窗體設置單選按鈕列表的AutoPostBack屬性false –

+0

試過它vignesh,沒有解決它。 - 其實嘗試將其設置爲false。還是一樣的 – rakesh

回答

0

我打電話兩個事件,那是什麼原因造成的不當行爲

 $(document).ready(function() { 
    $("#<%=releasetype.ClientID%>").click(function() { 

調用只有一個,無論是在頁面加載或按一下按鈕解決了這個問題。

相關問題