event.preventDefault似乎不起作用 [英] event.preventDefault doesn't seem to work

查看:113
本文介绍了event.preventDefault似乎不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我试图阻止表单刷新页面,这是我正在使用的代码:

So im trying to stop a form from refreshing the page and this is the code i'm using:

$("#getName").submit(function(refresh) {
    refresh.preventDefault();
    $("#p22").fadeOut(50);
    $("#p23").fadeIn(800);
    document.getElementById("p23").innerHTML = "Oh " + userName + ", alright i wont forget that!";

})

我似乎无法正常工作....

I can't seem to get this working properly....

id = getName-是表单ID

id = getName - is the form id

推荐答案

您的问题类似于: https://stackoverflow.com /a/6462306/986160

尝试一下:

$("#getName").submit(function(refresh) {
    $("#p22").fadeOut(50);
    $("#p23").fadeIn(800);
    $("#p23").html("Oh " + userName + ", alright i wont forget that!");
    return false;
})

通过返回false就像refresh.preventDefault()和refresh.stopPropagation()一样;)在此处查看详细信息: https://stackoverflow.com/a/1357151/986160

By returning false is like refresh.preventDefault() and refresh.stopPropagation() together ;) See details here: https://stackoverflow.com/a/1357151/986160

这篇关于event.preventDefault似乎不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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