输入提交按钮并输入

时间:2011-11-04 12:43:36

标签: jquery input submit enter

我通过点击明确的<input type="image">或回车键提交了很多表单。

使用的代码是:

<input width="62" type="image" height="22" border="0" onclick="flipSearchButton()" alt="Search" tabindex="9" src="/images/button-search.gif">

这些表单现已重新开发,代码如下所示

<a onclick="javascript:flipSearchButton();" class="button blue right" tabindex="9" href="javascript: submitform(&quot;main&quot;)">Search</a>

但是,由于更改,在单击回车键时不会提交表单。

如何让enter按钮提交表单?

表单的输入和清除按钮的html部分是:

  <div class="inline">
         <a class="icon blue left" onClick="javascript:resetForm();">Clear</a>
    </div>
    <div id="search_clickable">
          <a tabindex="14" class="button blue right" href="javascript:flipSearchButton();submitform('main')">Search</a>
    </div>
    <div id="search_unclickable" class="disp_none;">
          <a class="button blue right" href="">Searching...</a>
     </div>



<script type="text/javascript">
    function resetForm() {
        var formObj = document.main;
        formObj.subCategory.value = '';
        formObj.surname.value = '';
        formObj.includeSurnameVariants.checked = false;
        formObj.forenames.value = '';
        formObj.forenames.focus();
        formObj.includeForenamesVariants.checked = true;
        formObj.eventYear.value = '';
        formObj.eventYearTolerance[3].selected = true;              
        formObj.county.value = '';
    }   

    $(document).ready(function() {
        document.main.forenames.focus();
    });
</script>

2 个答案:

答案 0 :(得分:1)

试试这个:

<a class="button blue right" tabindex="9" 
    href="javascript:flipSearchButton();submitform('main')">Search</a>

答案 1 :(得分:1)

$('.submitme').keypress(function(e){
      if(e.which == 13){
         submitform('main');
      }
});

添加此代码,然后将类submitme添加到您希望表单在按下回车键时提交的输入字段 - 这将调用submitform()方法