2011-11-22 88 views
0

我有一个html表单来开发。但表格没有提交,直到我不按提交按钮。我想,当我们选择任何单选按钮复选框,然后按Enter键应当提交无法提交html表格

我的HTML是这样的:

<html> 
    <head> 
    <title>select preferences</title> 
    </head> 
    <body> 
    <input type="radio" name="sex" value="male" /> Male<br/> 
    <input type="radio" name="sex" value="female" /> Female<br/> 
    <button type="submit">Click Me!</button> 
    </body>   
</html> 

请帮我解决这个问题。并给出相关教程的一些链接。

+0

你应该为此定义一个默认按钮: –

+0

谢谢,Royi Namar。是的,它适用于我 – Kmme83

回答

0

在您的单选按钮change,使用提交表单:

$('#form-id').submit(); 

所以,你的HTML应该是:

<form id='form-id' method='post' action=''> 
<input type="radio" name="sex" value="male" /> Male<br/> 
<input type="radio" name="sex" value="female" /> Female<br/> 
<button type="submit">Click Me!</button> 
</form> 

和你的脚本应该是:

$(function(){ 
    $('input[type=radio]').change(function(){ 
     $('#form-id').submit(); 
    }); 
}); 
+0

“按输入它应该提交”.... –

+0

感谢赛义德Neamati你的帮助。 – Kmme83

4

您错过了<form>标记。

看一看here

+0

打我吧.. – Matt

0

添加表单标签

 
<form method="post" action="somepage"> 
//add you inputs here 
<form>