0

我有很多通过单击显式<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>

但是,自从更改后,单击回车键时不会提交表单。

如何使输入按钮提交表单?

表单的输入和清除按钮的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>
4

2 回答 2

1

尝试这个:

<a class="button blue right" tabindex="9" 
    href="javascript:flipSearchButton();submitform('main')">Search</a>
于 2011-11-04T12:44:59.247 回答
1
$('.submitme').keypress(function(e){
      if(e.which == 13){
         submitform('main');
      }
});

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

于 2011-11-04T17:04:46.593 回答