document.forms[0].submit() 中的 firefox 问题
我有一个表格要在 bodyLoad 上提交。
我编写了 document.forms[0].submit()
,它可以在 IE 9 和 Chrome 14 上正常工作,但在 FF 3.6.23 中不起作用。
有什么想法吗?这是 FF 的已知问题吗?
我尝试过其他选项,例如 document.form_name.submit()
和 document.getElementById('form_id').submit()
但对 FF 不起作用。
我在 FF 中遇到的错误是
document.forms[0]
未定义
这是我在视图中编写的内容(CakePHP 1.2.6):
<?php $this->layout = 'blank'; ?>
<?php e($form->create('Mymodel', array('name'=>'myform', 'url'=>'gohere'))); ?>
<?php e($form->hidden('name', array('value'=>$name))); ?>
<?php e($form->end()); ?>
<script language="javascript">
document.forms[0].submit();
</script>
I have a form which I want to submit on bodyLoad.
I have written document.forms[0].submit()
which works fine with IE 9 and Chrome 14 but same is not working in FF 3.6.23.
Any ideas? Is this a known issue with FF?
I have tried other options like document.form_name.submit()
and document.getElementById('form_id').submit()
but nothing works with FF.
The error I am getting in FF is
document.forms[0]
is undefined
This is what I have written in the view (CakePHP 1.2.6):
<?php $this->layout = 'blank'; ?>
<?php e($form->create('Mymodel', array('name'=>'myform', 'url'=>'gohere'))); ?>
<?php e($form->hidden('name', array('value'=>$name))); ?>
<?php e($form->end()); ?>
<script language="javascript">
document.forms[0].submit();
</script>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这在 Firefox 中不起作用,因为页面尚未完全加载。
消除
document.forms[0].submit();
并设置
注意不要将
That won't work in Firefox, since the page isn't fully loaded yet.
Eliminate
document.forms[0].submit();
and set
<body onLoad="document.forms[0].submit();">
Be careful not to point
<form>
to the current page, as it would cause an endless loop.JavaScript 代码可以在表单实际加载之前执行。这就是 Firefox 找不到 document.forms[0] 的原因。在执行 javascript 之前,您必须确保页面已准备好。使用 JQuery,您可以使用 $(document).ready() 来完成此操作
The javascript code may be executed before the form is actually loaded. That's why Firefox can't find document.forms[0]. You have to make sure your page is ready before executing javascript. With JQuery, you do it with $(document).ready()