繁体   English   中英

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

[英]How to submit the form in JavaScript using that form class name?

我正在尝试通过JavaScript提交表单,该表单是Google API动态提供的。

表单没有名称。 但它具有class 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>

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM