在display:none元素内提交表单字段 [英] Submit form fields inside display:none element

查看:3499
本文介绍了在display:none元素内提交表单字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个长的形式,我分成了6个步骤。加载表单时,将加载所有步骤,但只有第一步可见。其余的具有 display:none 的CSS,因此它们被隐藏。当步骤完成并使用Javascript验证时,当前步骤设置为 display:none ,新步骤设置为 display:block 。在最后一步,用户提交表单。但是,如预期,只提交页面中 display:block 元素中的字段。 display:none 的元素中的所有已填写字段将被忽略。

I have a long form that I've broken up into 6 steps. When the form is loaded, all of the steps are loaded, but only the first step is visible. The rest have CSS of display:none so they are hidden. As a step is completed and validated with Javascript, the current step is set to display:none and the new step is set to display:block. On the final step, the user submits the form. However, as expected, only the fields in display:block element on the page are submitted. All the completed fields in the elements with display:none are ignored.

是否有提交字段的方法在 display:none 元素中?

Is there a way to submit the fields inside the display:none elements?

如果没有,是否有另一种方法实现相同的效果? p>

If not, is there another way to achieve the same effect?

推荐答案

将它们设置为 visibility:hidden :absolute 。这些字段不会通过 display:none 发送到服务器,但会使用 visibility:hidden 。通过切换位置到绝对,您应该得到相同的视觉效果。

Set them to visibility:hidden and position:absolute instead. The fields will not be sent to the server with display:none, but will be with visibility:hidden. By also toggling "position" to "absolute" you should get the same visual effect.

更新这似乎不再是问题在任何当前浏览器(截至2015年11月)。即使显示设置为无,也提交字段。但是,已停用的字段将继续未提交。

Update This does not appear to be an issue anymore in any current browser (as of Nov of 2015). Fields are submitted even if display is set to 'none'. Fields that are 'disabled', however, will continue to not be submitted.

这篇关于在display:none元素内提交表单字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆