如何使用该表单类名称在JavaScript中提交表单?

时间:2012-01-05 07:18:08

标签: javascript

我正在尝试通过JavaScript动态提交来自Google API的表单。

表单没有名称。但它有班级name.my。问题是我想提交该表单使用它的类名。

<form class="gsc-search-box" accept-charset="utf-8">
<table cellspacing="0" cellpadding="0" class="gsc-search-box">
<tbody>
    <tr>
       <td class="gsc-input">
       <input type="text" autocomplete="off" size="10" class=" gsc-input" name="search" title="search" style="background: none repeat scroll 0% 0% rgb(255, 255, 255);" dir="ltr">
       </td>
       <td class="gsc-search-button">
       <input type="submit" value="Search" class="gsc-search-button" title="search">
       </td>
       <td class="gsc-clear-button">
         <div class="gsc-clear-button" title="clear results">
          &nbsp;
         </div>
       </td>
    </tr>
  </tbody>
  </table>
  <table cellspacing="0" cellpadding="0" class="gsc-branding">
     <tbody>
         <tr>
           <td class="gsc-branding-user-defined">
           </td>
           <td class="gsc-branding-text">
           <div class="gsc-branding-text">
                powered by
            </div>
            </td>
            <td class="gsc-branding-img">
            <img src="http://www.google.com/uds/css/small-logo.png" class="gsc-branding-img">
            </td>
          </tr>
       </tbody>
     </table>
   </form>

1 个答案:

答案 0 :(得分:3)

您需要做的是获取表单并调用其submit()方法,如下所示:

document.getElementsByClassName("gsc-search-box")[0].submit();