我有这个表单,需要在按下 ENTER 时提交。一切看起来都很好,但就是行不通。当单击搜索按钮工作正常但我也需要使用 ENTER 按钮时。
HTML 代码:
<form id="SearchForm" action="mysite.com/search" target="my-iframe" method="post">
<input type="text" id="x" class="dimmed" name="keywords[all_words]" />
<div class="fieldbg"><input type="text" id="y" class="dimmed" name="City[all_words]" /></div>
<type class="btn_search row_right" onclick="document.getElementById('SearchForm').submit()">
我尝试使用此脚本,但不起作用:
<script>
window.onload = function() {
var textbox = document.getElementById('x');
textbox.onkeypress = function (e) {
if (e.keyCode === 13) {
document.getElementById('SearchForm').submit();
}
};
}
</script>
最佳答案
首先,您的链接不正确:403 Forbidden;
第二,请检查页面中是否定义了SearchForm id :)
关于javascript - Enter 按钮不想将表单提交到 iframe,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15570848/