“提交不是一个函数” Firefox 中以动态创建的形式出现错误,没有其他提交输入

发布于 2024-11-29 01:12:29 字数 1131 浏览 4 评论 0原文

在 Firefox 5 的错误控制台(但不在 IE 9 中)中,当我调用以下 javascript 函数(在外部脚本文件中)时,出现错误“myForm.submit 不是函数”:

function go(url_go, arr_POST_vars, str_method) {
  var str_method = str_method || "POST";    // by default uses POST
  var myForm = document.createElement("form_redir");
  myForm.setAttribute("method", str_method);
  myForm.setAttribute("action", url_go);
  for (var key in arr_POST_vars) {
    var myInput = document.createElement("input");
    myInput.setAttribute("name", key);
    myInput.setAttribute("type", "hidden");
    myInput.setAttribute("value", arr_POST_vars[key]);
    myForm.appendChild(myInput);
  }
  document.body.appendChild(myForm);
  myForm.submit();
}

我的页面上唯一的 HTML(在 HTML 之间) body Tags) 是以下行:

<button type='button' onClick='javascript:go("http://www.testsite.com/login.php", {userCode:"2487",password:"jon123"}, "POST");'>Go!</button>

我已经在 Google 上进行了广泛的搜索,我知道当存在一个也名为“submit”的表单输入时会发生此错误,该输入与表单的“submit()”函数名称冲突。然而,这里的情况并非如此。

这里的想法是,通过动态创建表单,在单击按钮时导航并将 POST 值提交到特定的 url。它在 IE 中工作正常,但在 Firefox 中不行。

我很茫然,将非常感谢解决方案。

In Firefox 5's error console (but not in IE 9) I get the error "myForm.submit is not a function" when I call the following javascript function (in an external script file):

function go(url_go, arr_POST_vars, str_method) {
  var str_method = str_method || "POST";    // by default uses POST
  var myForm = document.createElement("form_redir");
  myForm.setAttribute("method", str_method);
  myForm.setAttribute("action", url_go);
  for (var key in arr_POST_vars) {
    var myInput = document.createElement("input");
    myInput.setAttribute("name", key);
    myInput.setAttribute("type", "hidden");
    myInput.setAttribute("value", arr_POST_vars[key]);
    myForm.appendChild(myInput);
  }
  document.body.appendChild(myForm);
  myForm.submit();
}

The only HTML on my page (between the HTML body tags) is the following line:

<button type='button' onClick='javascript:go("http://www.testsite.com/login.php", {userCode:"2487",password:"jon123"}, "POST");'>Go!</button>

I have Googled extensively, and I know that this error occurs when there is a form input which is also named "submit", which then clashes with the "submit()" function name of the form. However this is not the case here.

The idea here is to navigate and submit POST values to a specific url when the button is clicked, by creating a form dynamically. It works fine in IE but not Firefox.

I am at a loss and a solution will be deeply appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

╄→承喏 2024-12-06 01:12:30

这是由您创建的元素类型引起的。 “form_redir”不是有效的 html 标签,因此它创建了一个元素,但它只有默认的 dom 方法。改成“form”就可以了。

Its caused in the type of element you've created. "form_redir" is no valid html tag so it created an element but it has only the default dom methods. Change it to "form" and it will work.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文