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;在我的代码中。但是这两种方法都没有阻止页面刷新。
请显示实际的HTML代码,而不是我们无法轻易再现的服务器端代码。 [mcve] – CBroe
嗨你正在使用ASP .NET的Web窗体设置单选按钮列表的AutoPostBack属性false –
试过它vignesh,没有解决它。 - 其实尝试将其设置为false。还是一样的 – rakesh