事件错误.预防默认

Errors with event.preventdefault

本文关键字:默认 错误 事件      更新时间:2023-09-26

这不起作用

.JS:

   var currentPath = window.location.pathname;    var currentPage = currentPath.substring(currentPath.lastIndexOf('/') + 1);        $(函数() {            $("#shoutBox").submit(function(event) {                event.preventDefault();                var 值 = $('#shoutBox').serialize();                $.post("shoutbox.php", values)                .done(function(data) {                    $('input:text[name=shout]').val("JE SHOUT IS GEPOST!瓦赫特 1 米努特!                    $('input:text[name=shout]').attr('readonly', true);                    设置超时(                        函数()                        {                            $('input:text[name=shout]').val("JE KAN EEN NIEUWE SHOUT MAKEN!");                            $('input:text[name=shout]').attr('readonly', false);                        }, 60000);                });            });        });        $(函数() {            $("#newName").submit(function(event) {                event.preventDefault();                var valuen = $('#newName').serialize();                $.post("shoutbox.php", valuen)                .done(function(data) {                    重新加载();                });            });        });    功能to_new_page(链接)    {        $("#content").fadeOut(function()            {                $(this).load(link+" #content", function()                {                    $(this).fadeIn();                })            });        history.pushState({change: "page"}, "RandomRadio", "/"+link);    }    函数重装()    {        to_new_page(当前页);    }

表格 #shoutBox 工作成功。
但是当我 #newName 两次提交表单时,它将刷新页面。

也许是因为你的.donereload()

不过,我要补充return false;

$("#newName").submit(function(event) {
            event.preventDefault();
            var valuen = $('#newName').serialize();
            $.post("shoutbox.php", valuen)
            .done(function(data) {
                reload();
            });
            return false;
        });

请修正您的报价。选择单引号或双引号并坚持下去。

我有一个修复:)

我在提交按钮中添加了一个 ID 并使用了这个

   $("#submitshout").live("click", function(event){

而不是

   $("#shoutBox").submit(function(event) {