我正在创建一个在javascript函数中提交的表单.我将函数绑定到select元素的onchange事件.事件在chrome和firefox中运行良好,我测试了它,它调用了函数.但问题是;虽然chrome提交表单,但firefox没有.能否请你帮忙?
谢谢.
function getStatementDetails()
{
var stmtSelect = document.getElementById("statementSelect");
var selectedId = stmtSelect.options[stmtSelect.selectedindex].value;
var stmtForm = document.createElement("form");
stmtForm.setAttribute('method',"post");
stmtForm.setAttribute('action',"mymiles-mystatement");
var stmtId = document.createElement("input");
stmtId.setAttribute('type',"hidden");
stmtId.setAttribute('name',"statementID");
stmtId.setAttribute('id',"statementID");
stmtId.setAttribute('value',selectedId);
stmtForm.appendChild(stmtId);
stmtForm.submit();
};
选择输入:
编辑:
我已阅读建议的帖子并尝试过.还是行不通.
功能最新状态:
function getStatementDetails()
{
var stmtSelect = document.getElementById("statementSelect");
var selectedId = stmtSelect.options[stmtSelect.selectedindex].value;
var stmtForm = document.createElement("form");
stmtForm.setAttribute('method',selectedId);
var stmtSbmt = document.createElement("input");
stmtSbmt.setAttribute('type',"submit");
stmtSbmt.setAttribute('name',"tryMe");
stmtSbmt.setAttribute('id',"tryMe");
stmtSbmt.setAttribute('value',"try submit");
stmtForm.appendChild(stmtId);
stmtForm.appendChild(stmtSbmt);
stmtForm.submit();
};
最佳答案
评论部分已满,可能是用户看不到正确的答案. @spuyet说这是解决方案:
Javascript form.submit() not working in Firefox
似乎firefox没有发送没有任何按钮的表单.如果您的代码中包含提交按钮,则必须正常工作.
var button = document.createElement("input");
button.setAttribute('type',"submit");
stmtForm.appendChild(button);
而且我认为这可以解决您的问题.
请告诉我们你是否解决了.
原文地址:https://www.jb51.cc/html/426558.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。