我正在尝试通过 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">
</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();
关于javascript - 如何使用该表单类名在 JavaScript 中提交表单?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8738933/