Javascript document.form.submit() 不适用于 Firefox 4.0 和 IE8

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5547960/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 17:35:14  来源:igfitidea点击:

Javascript document.form.submit() not working with Firefox 4.0 and IE8

internet-explorer-8firefox4javascript

提问by Sathyan A

I'm trying to submit a form with javascript. Works fine with Firefox 3.6, but doesn't work in Firefox4.0 and IE8.

我正在尝试使用 javascript 提交表单。适用于 Firefox 3.6,但不适用于 Firefox4.0 和 IE8。

Code:

代码:

<table>  
     <tr>
     <td>  
     <form action='results.html' method='post' target='_blank' id='<% $question->{ QuestionID } %>'>  
     <input type='hidden' name='SurveyID' value='<% $surveyid %>'  
     <input type='hidden' name='responses' value='<% join ",", map { $_->{ srid } } @textresults %>'/>  
     <input type='hidden' name='question' value='<% $question->{ QuestionID } %>'/>  
Total Responses: (< a href='javascript: submitForm("<% $question->{ QuestionID } %>");' >View All< /a>)  
     </form>  
     </td>  
     </tr>  
</table>  

Javascript:

<script type='text/javascript'>  
function submitForm(id) {  
document.getElementById(id).submit();  
}  
</script>  

Any Idea what is wrong?

任何想法有什么问题?

采纳答案by Rian Schmits

First of all close the first input tag like this: <input type='hidden' name='SurveyID' value='<% $surveyid %>'/>. Also remove the spaces from the atag, here: <a hrefand here: </a>

所有接近第一输入标签这样的第一:<input type='hidden' name='SurveyID' value='<% $surveyid %>'/>。还要从a标签中删除空格,这里:<a href和这里:</a>

回答by lmondria

What happens if you add a name property to the form and submit the form like this:

如果您向表单添加 name 属性并像这样提交表单会发生什么:

function submitForm(id) {  
  document.formname.submit();
}