当按下ENTER键时,表单不发送到服务器
Form not posting to server when ENTER key is pressed
我有一个显示用户名的简单div:
<div id="firstNameChange" title="Click to edit" style="vertical-align:top; display:inline-block; float:left;"><?=$firstName?></div>
当用户用鼠标点击div时,它会变成一个表单:
<form method="post" action="" >
<div id="firstNameChange" title="Click to edit" style="vertical-align:top; display:inline-block; float:left;"><?=$firstName?></div>
<input type="hidden" name="firstName" id="firstName" value="<?=$firstName?>"/>
<input type="submit" name="submitFirstName" id="saveFirstName" class="ui-icon ui-icon-disk" style="border:none; display:none; background-color:transparent; float:right; vertical-align:top;" />
</form>
使用jQuery:
$("#firstNameChange").click(function() {
//check if there are any existing input elements
if ($(this).children('input').length == 0) {
$("#saveFirstName").css("display", "inline");
//variable that contains input HTML to replace
var inputbox = "<input type='text' class='inputbox' name='firstName' value='""+$(this).text()+"'">";
//insert the HTML intp the div
$(this).html(inputbox);
//automatically give focus to the input box
$(".inputbox").focus();
//maintain the input when it changes back to a div
$(".inputbox").blur(function() {
var value = $(this).val();
$("#firstName").val(value);
$("#firstNameChange").text(value);
});
}
});
问题是表单只有在用鼠标单击Submit按钮时才会发送回服务器。如果用户按了键盘上的回车键,它就不会返回。有什么建议吗?
找到答案了。我移除了隐藏元素,一切都运行良好。感谢大家的支持!
相关文章:
- Nodejs服务器在解析之前生成输入表单
- Javascript未在开发服务器上填充Perl表单
- JavaScript表单提交没有't fire asp服务器端点击功能的提交按钮
- 表单的服务器端验证
- 如何通过ajax php将图像上传到服务器本地目录,其中html表单haven't任何传统的提交按钮
- 在此服务器上找不到请求的-表单验证(位于localhost端口80的Apache/2.4.9(Win32)PHP/5.5
- REST API 服务器是否应该使用 PUT 接收 JSON 数据或普通表单数据
- 如何使用angular js在表单上显示服务器端验证错误消息
- 缺少用于创建的模板.内部服务器错误-聚合物表单保存到数据库
- 将从服务器获取的数据加载到输入文本表单中
- 如何在没有Ajax的情况下将blob存储在表单中,并在单击提交时将其发送到服务器
- 如何从服务器获取和设置表单的默认值
- 如果我使用html表单(而不是ajax),则获取服务器的响应代码或返回值
- ASP表单在服务器上运行,不允许内部HTML按钮onlick setInterval工作
- 如何实现自定义 Auth0 登录表单的服务器端代码
- 使用 AngularJS Http Post 将表单 html 中的数据发布到服务器
- 如何进行表单验证,并在单击按钮时以同一脚本将表单数据发布到服务器
- 如何将服务器端类型传递给 asp.net Web 表单以供 JavaScript 使用
- 如何在 ASP.NET Web 表单中填补服务器端和客户端之间的空白
- 服务器仅在表单提交时调用 preventDefault 时返回 500 错误