简体   繁体   English

Firefox 在没有其他提交输入的情况下以动态创建的形式出现“提交不是函数”错误

[英]“Submit is not a function” error in Firefox in dynamically CREATED form without other submit inputs

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):在 Firefox 5 的错误控制台(但不在 IE 9 中)中,当我调用以下 javascript ZC1C425268E68385D1AB5074C17A94F 文件时,我收到错误“myForm.submit is not a function”

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:我页面上唯一的 HTML (在 HTML 正文标签之间)是以下行:

<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.我已经广泛搜索,并且我知道当有一个表单输入也称为“提交”时会发生此错误,然后与表单的“提交()”function 名称发生冲突。 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.这里的想法是通过动态创建表单,在单击按钮时导航并将 POST 值提交到特定的 url。 It works fine in IE but not Firefox.它在 IE 中运行良好,但在 Firefox 中运行良好。

I am at a loss and a solution will be deeply appreciated.我很茫然,一个解决方案将不胜感激。

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. “form_redir”不是有效的 html 标记,因此它创建了一个元素,但它只有默认的 dom 方法。 Change it to "form" and it will work.将其更改为“形式”,它将起作用。

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

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