我正在使用显示和隐藏锚标记来存储某些数据。但是,每次我单击“显示”或“隐藏”标签时,页面都会回到顶部,并且我必须向下滚动才能看到详细信息。如何防止这种情况,请指导我。我正在使用javascript函数显示和隐藏详细信息。
<script type="text/javascript">
$(document).ready(function () {
$(".productDescription").hide();
$(".show_hide").show();
$(".hide_show").hide();
$('.show_hide').click(function () {
$(this).parent().find('.productDescription').slideToggle();
$(this).parent().find(".show_hide").hide();
$(this).parent().find(".hide_show").show();
});
$('.hide_show').click(function () {
$(this).parent().find('.productDescription').slideToggle();
$(this).parent().find(".show_hide").show();
$(this).parent().find(".hide_show").hide();
});
});
</script>
这是我的aspx页面
<div class="product clearfix"> <a href="#" class="show_hide" style="color: #FF0000" id="FD">Full Description</a>
<br /> <a href="#" class="hide_show" style="color: #FF0000" id="HFD">Hide Full Description</a>
<div class="productDescription">
<p>
<asp:Label ID="im_url" runat="server" Text='<%# Eval("description") %>'></asp:Label>
</p>
</div>
</div>
您可以尝试像这样添加preventDefault吗?由于锚定标记的href包含#,因此#将附加到url并执行锚定标记的默认行为。
$('.show_hide').click(function (evt) {
evt.preventDefault();
$(this).parent().find('.productDescription').slideToggle();
$(this).parent().find(".show_hide").hide();
$(this).parent().find(".hide_show").show();
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句