2014-09-29 46 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。

相關問題