无论我做什么,我的表单总是在点击按钮时提交

Lin*_*say 1 html javascript forms jquery

我有一个相对简单的形式.我正在使用jQuery来选择提交按钮,截至目前,我只是在点击时显示警告.

问题:无论我做什么,按钮都使用它的默认动作.所以基本上没有警报显示,我坚持使用提交的参数,这些参数被附加到地址栏中url的末尾.

我已经尝试使用e.preventDefault();,e.preventDefault(true);,e.stopImmediatePropogation(),和e.stopImmediatePropogation(true);.

我甚至试过将它们放在一个document.ready()区块中.

注册表格是一个模态面板,但我认为这不重要...(应该吗?)

我想我现在会告诉你代码.我真的不明白为什么它不起作用.我很感激任何帮助:

HTML:http://pastebin.com/bHCC58w4(完整文档)

    <form id="registerForm">
        <a class="close"></a>
        <h3>Register Today! - It's FREE!</h3>
        <p>Registering only takes seconds, and puts you into direct contact with a designer. On top of all that, you can add documents, images, and other files to your project dashboard. What are you waiting for? It's free!</p>
        <img src="images/formfish.png" alt="Goldy the goldfish helps users register. It looks like he stepped out for a minute. Sorry about that!" />
        <input type="text" id="name" name="name" placeholder="Your full name." title="We just need your first and last name." class="masterTooltip" />
        <input type="email" id="email" name="email" placeholder="Your email." title="We won't send you spam. Pinky swear." class="masterTooltip"  />
        <input type="text" id="userName" name="userName" placeholder="Your username." title="Your username must be unique." class="masterTooltip" />
        <input type="password" id="password" name="password" placeholder="Your password." title="Make your password hard to guess." class="masterTooltip" />
        <button id="register">Sign up</button>
    </form>
Run Code Online (Sandbox Code Playgroud)

JAVASCRIPT:http://pastebin.com/bD2fYPsh(完整文档)

        $("#register").on("click", function(e){
            e.preventDefault();
            alert("Hello!");
        });
Run Code Online (Sandbox Code Playgroud)

这是该网站的半实时版本.除了jQuery动画之外,它没有其他功能.我不知道它是否会帮助你们:http://graphicgoldfish.com/creativecodefish/

Hau*_*Haf 5

更改按钮,这只是一个按钮,而不是提交按钮:

<button id="register" type="button">Sign up</button>
Run Code Online (Sandbox Code Playgroud)

默认情况下,按钮属于submit类型,这将导致表单本身提交.