jQuery单击将我带到页面顶部.但我想留在原地 [英] jQuery click brings me to top of page. But I want to stay where I am

查看:64
本文介绍了jQuery单击将我带到页面顶部.但我想留在原地的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的单击并显示,单击并隐藏的按钮,但是当我单击它时,页面锚定在页面顶部.反正有防止这种情况发生的方法吗?这样,当我单击按钮时,我会停留在浏览器中的同一位置吗?

I have a simple click and show, click and hide button, but when I click it, the page anchors at the top of the page. Is there anyway to prevent this? So that when I click the button, I stay at the same place in the browser?

我的代码是..

$('#reportThis').hide();

$('#flagThis').click(function () {
    $('#reportThis').show("slow");
});
$('#submitFlag').click(function () {
    $('#reportThis').hide("slow");
});

推荐答案

尝试一下:

$('#reportThis').hide();

$('#flagThis').click(function (evt) {
        $('#reportThis').show("slow");
        evt.preventDefault();
});
$('#submitFlag').click(function (evt) {
        $('#reportThis').hide("slow");
        evt.preventDefault();
});

这篇关于jQuery单击将我带到页面顶部.但我想留在原地的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆