document.forms[0].submit() 中的 firefox 问题

发布于 2024-12-09 03:52:33 字数 777 浏览 6 评论 0原文

我有一个表格要在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

留一抹残留的笑 2024-12-16 03:52:33

这在 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.

沫尐诺 2024-12-16 03:52:33

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()

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文