javascript - HTML 多页表单问题(页面正在刷新)

标签 javascript html forms

我在提交多页表单时遇到问题。问题是当我按下下一页按钮时页面正在刷新。我相信这是一个返回真/假的问题,但我不知道问题出在哪里。这是代码:

$(document).ready(function () {
        var info = [];
        function showinfo() {
            for (i=0; i<info.length; i++) {
                $('#step3 ul').append(
                    $('<li>' + info[i] + '</li>')
                );
            };
        };
        $('#step1_btn').click(function() { 
            $("input").each(function() {
                if (input.type != radio) {
                    info.push(this.name+':'+this.value);
                } else if ($('.radio').is(':checked')) {
                    info.push(this.name+':'+this.value);
                }
            });
            $('#step1').css('display','none');
            $('#step2').css('display','inherit');
            $('#progbar').attr('value',33);
            return false;
        });
        $('#step2_btn').click(function() {
            $("input").each(function() {
                if (input.type != radio) {
                    info.push(this.name+':'+this.value);
                } else if ($('.radio').is(':checked')) {
                    info.push(this.name+':'+this.value);
                }
            });
            $('#step2').css('display','none');
            $('#step3').css('display','inherit');
            $('#progbar').attr('value',66);
            showinfo();
            return false;
        });
    });

不确定这是否就是您需要看到的全部内容。如果您还需要查看 html,我可以提供。预先感谢大家可以提供的任何帮助。当别人编写 JavaScript 时,我可以很好地阅读它,但由于某种原因,我自己编写的每次都会陷入灾难。

最佳答案

尝试event.preventDefault() :

$('#step1_btn').click(function(e) { 
   e.preventDefault();
   // your code here
   return false;
});

关于javascript - HTML 多页表单问题(页面正在刷新),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13225206/

相关文章:

javascript - Tic-Tac-Toe 游戏——Regex 想要比 3x3 棋盘中更多的字符吗?

javascript - 如何使我的正则表达式匹配文本中的任何类型的 str

html - 无法在打印预览中更改 h1 字体大小

html - 如何使高度自动包装器根据 Logo 的高度展开

html - 使用浏览器后退按钮返回时清除表单中的所有字段

javascript - Javascript 中的控制流和迭代

javascript - 使用链接或按钮触发 JVectorMap 向下钻取

javascript - 使用来自字段的值在页面加载时运行 jQuery

forms - Symfony 2.2 - 在开发环境中登录后重定向错误

html - 在输入字段中使用 'autofocus' 时,Firefox 中无样式内容 (FOUC) 的闪烁