如何在使用“显示和隐藏锚定标记”时防止滚动页面
How to prevent scrolling of page while using Show and Hide anchor tag?
我对一些数据使用显示和隐藏锚点标记。但每次我点击"显示"或"隐藏"标签时,页面都会回到顶部,我必须向下滚动才能查看详细信息。如何防止这种情况发生,请指导我。我正在使用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();
});
您必须使用preventDefault(防止本地行为)方法,如下所示:
$('.show_hide').click(function (ev) {
ev.preventDefault();
// Your code goes here
})
相关文章:
- Image赢得't隐藏在滚动jQuery上
- 禁用(而不是隐藏)浏览器滚动条
- 在滚动时,在隐藏滚动条和隐藏溢出的同时触发事件
- 滚动定位时隐藏标题
- 如何隐藏滚动条,但希望它继续工作
- ajax显示隐藏滚动到最重要的问题
- 隐藏元素后更新滚动条
- 如何在模式窗口弹出窗口中隐藏滚动条
- 向下滚动时隐藏菜单,向上滚动时显示,适用于Chrome,不适用于Safari(手机)
- 我如何从一个无限滚动的网站抓取图像,其中api是隐藏的,我无法通过使用Inspect Element获得它->网络
- 在可滚动表中隐藏垂直滚动
- 使用溢出时隐藏滚动条:滚动;但保持滚动能力
- 在离子滚动时隐藏离子导航栏
- 允许在隐藏溢出的情况下进行触摸滚动
- 带滚动条的Div位于带溢出的Div内:隐藏
- 如何在使用“显示和隐藏锚定标记”时防止滚动页面
- Jquery干扰后隐藏垂直滚动条
- AngularJS:使用$animate隐藏滚动中的元素
- 使用窗口滚动而不是容器滚动隐藏
- 无限滚动隐藏第一个元素