无法提交html表格
问题描述:
我有一个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>
请帮我解决这个问题。并给出相关教程的一些链接。
答
在您的单选按钮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
答
添加表单标签
<form method="post" action="somepage"> //add you inputs here <form>
你应该为此定义一个默认按钮: –
谢谢,Royi Namar。是的,它适用于我 – Kmme83