【问题标题】:Submit a form without ID using Javascript使用 Javascript 提交没有 ID 的表单
【发布时间】:2018-07-14 07:36:29
【问题描述】:

我有一个没有任何 ID 的表单。

<form action="LoginServlet" method="post" onsubmit="return checkForm(this);">

如何让表单提交?

我只有那个页面上的表格,所以我尝试了这个,但它不起作用。

document.forms[0].submit()

【问题讨论】:

  • “没用” 不是问题描述。控制台有错误吗?
  • 更多代码?我测试成功了
  • 使用browser console (dev tools)(点击F12)并阅读任何错误。你有一个<input>name="submit"If you don’t rename that button, you can’t use the submit function.
  • @nitesh 如果您尝试提交表单,它将无法工作,因为它有验证码。以编程方式提交会很困难,因为它有验证码。
  • @parag 我已经直接输入了验证码。然后我需要执行“登录”操作。 document.getElementById('captcha').value = '(value)';

标签: javascript jquery forms


【解决方案1】:

试试这个,根据你提供的网址测试没问题:

document.getElementsByClassName('btn btn-primary')[0].click();

下面的代码不起作用,因为该网站有一个名称为“提交”的输入

document.forms[0].submit()

所以,当你执行时

document.forms[0].submit//returns an input element,not a function

所以,

document.forms[0].submit() //doesn't work,cause document.forms[0].submit is not a function

【讨论】:

  • 'document.getElementsByClassName('btn btn-primary')[0].click();'这也没有用。
  • @Nitesh ,这个网址:passbook.epfindia.gov.in/MemberPassBook/Login.jsp ?我测试成功了
  • 对不起,它有效。现在的问题是我以这种方式设置的密码文本 'document.getElementById('password').value = 'passwordhere';'你能帮我解决这个问题吗?如果我这样设置,我会收到错误密码不可用。
  • @Nitesh 你设置对了,我测试对了,有什么问题?
  • 对不起,这只是我的代码中的拼写错误。感谢帮助! :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-04-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-01-10
  • 2011-08-31
  • 1970-01-01
相关资源
最近更新 更多