javascript – jQuery click让我回到页面顶部.但我想留在原地

栏目: jQuery · 发布时间: 6年前

内容简介:翻译自:https://stackoverflow.com/questions/976753/jquery-click-brings-me-to-top-of-page-but-i-want-to-stay-where-i-am

我有一个简单的点击和显示,点击和隐藏按钮,但当我点击它时,页面锚定在页面的顶部.反正有没有阻止这个?那么当我点击按钮时,我会在浏览器中停留在同一个地方?

我的代码是……

$('#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();
});

翻译自:https://stackoverflow.com/questions/976753/jquery-click-brings-me-to-top-of-page-but-i-want-to-stay-where-i-am


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Design Accessible Web Sites

Design Accessible Web Sites

Jeremy Sydik / Pragmatic Bookshelf / 2007-11-05 / USD 34.95

It's not a one-browser web anymore. You need to reach audiences that use cell phones, PDAs, game consoles, or other "alternative" browsers, as well as users with disabilities. Legal requirements for a......一起来看看 《Design Accessible Web Sites》 这本书的介绍吧!

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

URL 编码/解码
URL 编码/解码

URL 编码/解码