2014-09-29 78 views
0

这是我的HTML:我可以做到这一点吗,点击单选按钮不提交表单?

<form class="form-signin" role="form" action="#" onclick="return signup(this);"> 
    <h2 class="form-signin-heading">Please sign up</h2> 
    <input type="text" id="name" class="form-control" placeholder="Name" required autofocus> 
    <input type="email" id="email" class="form-control" placeholder="Email address" required> 
    <input type="password" id="password" class="form-control" placeholder="Password" required> 
    <input type="radio" name="member-type" value="student">Student</input> <br> 
    <input type="radio" name="member-type" value="parent">Parent</input> <br> 
    <input type="radio" name="member-type" value="alumnus">Alumnus</input> <br> 
    <br> 
    <button class="btn btn-lg btn-primary btn-block" type="button">Sign up</button> 
</form> 

当我点击单选按钮,他们提交表单。如果我把onclick放在button标签里面,那么我不能再使用“return signup(this);”。有没有解决这两个问题的方法?

+0

有更好的方法来做你需要的东西比在表单元素提交表单 – kinakuta 2014-09-29 00:31:04

+0

你能详细说明一个onclick处理程序吗? – lethargicsloth 2014-09-29 00:36:30

+0

“返回注册(这个)”是做什么的,为什么你认为你不能使用它?你是否试图用按钮提交表单?是否有任何理由不使用表单的'onsubmit'事件? – Guffa 2014-09-29 00:37:29

回答

0

在您的返回注册功能中,如果您不希望表单提交,请返回false。

如果你这样做,你可以运行特定的验证你的表单。如果你想要提交表单,只需在你的函数中返回true即可。

我也会将您的按钮更改为在您的表单标记中键入=“submit”并将onClick参数更改为onSubmit。