【问题标题】:js submit button displaying 'submit query', not functioning, only in IE Edge / IE *js 提交按钮显示“提交查询”,不起作用,仅在 IE Edge / IE 中 *
【发布时间】:2016-07-27 17:33:12
【问题描述】:

让这个表单由 javascript 生成。它适用于除 IE Edge 和以前版本的 IE 之外的所有浏览器。我已经对此进行了研究并进行了调查,但没有提出任何答案。它适用于所有其他经过测试的浏览器,但在 IE 中,提交按钮值为“提交查询”并且无法提交表单。此 javascript 内嵌在标签下方的页面上。我难住了。非常感谢任何帮助。

/*generate the form itself */
var loginForm = document.createElement("form");
    loginForm.setAttribute('id',"editDataForm");
    loginForm.setAttribute('method',"post");
    loginForm.setAttribute('action',"submit.cfm");

/*some basic text field */
var someTextBox = document.createElement("input");
    someTextBox.setAttribute('type',"text");
    someTextBox.setAttribute('name',"username");

/*submit button */
var submitThis = document.createElement("input");
    submitThis.setAttribute('value',"Submit");
    submitThis.setAttribute('type',"submit");
    submitThis.setAttribute('name',"SendFormAction");

/*append the textbox to the form */
loginForm.appendChild(someTextBox);

/*append the submit button to the form */
loginForm.appendChild(submitThis);

/*get the div where the form will generate itself */
var loginDiv = document.getElementById("submitFormArea");

/*append the form to the div */
loginDiv.appendChild(loginForm);

【问题讨论】:

  • Moving value after type 为我解决了这个问题。
  • 哇。同样在这里。这非常简单,但令人困惑。
  • 似乎设置type 会导致元素“重置”。哪种有意义,因为从默认(文本输入)更改为提交(按钮)是一个巨大的变化。

标签: javascript forms internet-explorer submit microsoft-edge


【解决方案1】:

取自 cmets,解决方法是改变这个:

/*submit button */
var submitThis = document.createElement("input");
    submitThis.setAttribute('value',"Submit");
    submitThis.setAttribute('type',"submit");
    submitThis.setAttribute('name',"SendFormAction");

到这里:

/*submit button */
var submitThis = document.createElement("input");
    submitThis.setAttribute('type',"submit"); // <-- Set type before value
    submitThis.setAttribute('value',"Submit");
    submitThis.setAttribute('name',"SendFormAction");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-04-19
    • 1970-01-01
    • 2015-02-17
    • 2013-03-11
    • 2012-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多